[英]Python: Converting file to base64 encoding
这是我的代码:
import base64
with open('/Users/Bob/test.txt') as f:
encoded = base64.b64encode(f.readlines())
print(encoded)
我基于base64文档 。 但是,当我尝试使用Python 2.7.1和Python 3.2.2运行它时,我收到错误:
import base64
File "/Users/Bob/test.txt'", line 4, in <module>
encoded = base64.b64encode(f.readlines())
AttributeError: 'module' object has no attribute 'b64encode'
为什么找不到b64encode
属性?
你有一个名为base64.py
的脚本,它正在影响stdlib模块。 重命名它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.