相关疑难解决方法(0)

Python:将文件转换为base64编码

这是我的代码:

import base64

with open('/Users/Bob/test.txt') as f:
    encoded = base64.b64encode(f.readlines())
    print(encoded)
Run Code Online (Sandbox Code Playgroud)

我基于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'
Run Code Online (Sandbox Code Playgroud)

为什么找不到该b64encode属性?

python

21
推荐指数
1
解决办法
2万
查看次数

标签 统计

python ×1