如何在base64字符串中的目录中转换多个文档并保存在文本文件中

时间:2019-08-06 05:59:15

标签: python python-3.x

我想将特定目录中的多个简历转换为base64 字符串并同时将其保存到文本文件中。

到目前为止我尝试过的事情

import base64
import sys

with open("filename.pdf", "rb") as pdf_file , open("filename.pdf","w") as output:
    encoded_string = base64.b64encode(pdf_file.read(),output.write())

I got this error when I execute the code

Traceback (most recent call last):
  File "encode.py", line 5, in <module>
    encoded_string = base64.b64encode(pdf_file.read(),output.write())
TypeError: write() takes exactly one argument (0 given)

1 个答案:

答案 0 :(得分:1)

应该是:

output.write(base64.b64encode(pdf_file.read()))

或:

encoded_string = base64.b64encode(pdf_file.read())
output.write(encoded_string)