python - 如何将目录中的多个文档转换为base64字符串并保存在文本文件中
问题描述
我想将特定目录中的多个简历转换为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)
解决方案
应该:
output.write(base64.b64encode(pdf_file.read()))
或者:
encoded_string = base64.b64encode(pdf_file.read())
output.write(encoded_string)
推荐阅读
- python - 在 Python(多处理)中正确腌制和取消腌制代理对象?“ConnectionRefusedError:[Errno 111] 解封时连接被拒绝”
- wordpress - 如何正确指向 Gulpfile.js 中的文件
- android - RecyclerView Kotlin,无法将回收器小部件添加到布局
- php - 如何在推送通知中显示图标?
- java - 以编程方式读取属性文件时,Log4J2 不记录任何内容
- android - 移动到另一个活动并返回时如何保存活动状态?
- reactjs - React JS 导入 css 文件有表达式 no-unused-expressions
- sql-server - 过程或函数“SlctNxtPrv”需要参数“@PRV”,但未提供?
- python - Django选择与条件间接相关
- c# - 希望随机化不同的可能输出