【发布时间】:2016-03-30 02:06:04
【问题描述】:
我目前正在开始使用 python,并编写一个程序,该程序将转换给定的长字符串十六进制数字,应该分成对。我很难使用 python 编码功能。
到目前为止,我有:
import base64
def splitByTwo(str):
return [i+j for i,j in zip(list(str)[::2], list(str)[1::2])]
def bytesToBase64(str):
b64List = []
stringsByTwo = splitByTwo(str.upper())
for x in stringsByTwo:
b64List.insert(stringsByTwo.index(x), base64.b16decode(x))
return b64List
print(bytesToBase64("49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d"))
我可以让它打印[b'I', b"'", b'm', b'm', b'm', b' ', b' ',.....],但我不确定我的bytesToBase64() 方法的base64 部分的编码/解码有什么问题。
【问题讨论】: