【发布时间】:2019-02-24 22:08:01
【问题描述】:
所以我正在尝试创建一个非常简单的程序来打开文件,读取文件并使用 python3 将其中的内容从十六进制转换为 base64。
我试过这个:
file = open("test.txt", "r")
contenu = file.read()
encoded = contenu.decode("hex").encode("base64")
print (encoded)
但我得到了错误:
AttributeError: 'str' object has no attribute 'decode'
我尝试了多种其他方法,但总是遇到相同的错误。
test.txt 里面是:
4B
如果你们能解释我做错了什么,那就太棒了。
谢谢
编辑:
我应该得到Sw== 作为输出
【问题讨论】:
标签: python python-3.x type-conversion base64 hex