我想将特定目录中的多个简历转换为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)
答案 0 :(得分:1)
应该是:
output.write(base64.b64encode(pdf_file.read()))
或:
encoded_string = base64.b64encode(pdf_file.read())
output.write(encoded_string)