Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 解码不带换行符的base64字符串_Python_Python 3.x_Base64 - Fatal编程技术网

Python 解码不带换行符的base64字符串

Python 解码不带换行符的base64字符串,python,python-3.x,base64,Python,Python 3.x,Base64,我正在处理一些base64数据。预期输出为6个十六进制数,如第一个示例中所示。但是,有时我会得到一个换行符,如第二个示例中所示(具有5个十六进制值) 我怀疑我得到了值0A,它被转换为换行符。修剪换行符时,我遗漏了一个十六进制值,\n只是来自\uuuuu repr\uuu中bytearray的字符串表示。将字节数组的内容提取到一个列表中,就可以得到您想要的: [p for p in base64.b64decode('DAAKRRTT')] # Output: [12, 0, 10, 69, 20

我正在处理一些base64数据。预期输出为6个十六进制数,如第一个示例中所示。但是,有时我会得到一个换行符,如第二个示例中所示(具有5个十六进制值)


我怀疑我得到了值0A,它被转换为换行符。修剪换行符时,我遗漏了一个十六进制值,
\n
只是来自
\uuuuu repr\uuu
中bytearray的字符串表示。将字节数组的内容提取到一个列表中,就可以得到您想要的:

[p for p in base64.b64decode('DAAKRRTT')]
# Output: [12, 0, 10, 69, 20, 211]
或者,用十六进制表示:

[hex(p) for p in base64.b64decode('DAAKRRTT')]
# Output: ['0xc', '0x0', '0xa', '0x45', '0x14', '0xd3']
[p for p in base64.b64decode('DAAKRRTT')]
# Output: [12, 0, 10, 69, 20, 211]
[hex(p) for p in base64.b64decode('DAAKRRTT')]
# Output: ['0xc', '0x0', '0xa', '0x45', '0x14', '0xd3']