docx2txt TypeError: write() argument must be str, not bytes
来源:互联网 发布:php 生成文本文件 编辑:程序博客网 时间:2024/05/21 22:58
最近在做一个从doc文件中提取图片的实验,可是报了一个错误TypeError: write() argument must be str, not bytes
python 3我的代码为
import osimport docx2txtclass fileUtil(): ''' 删除其它格式的文件,保留图片格式的文件 ''' def deleteFiles(self,dirs): for file in dirs: # print dr # print(file) fileArray = file.split(".") if fileArray[-1] == "pdf": # 删除pdf文档 # print(file) os.remove(os.path.join(path, file)) print(file) elif fileArray[-1] == "docx": # 删除pdf文档 # print(file) os.remove(os.path.join(path, file)) print(file) elif fileArray[-1] == "doc": # 删除pdf文档 # print(file) os.remove(os.path.join(path, file)) print(file) def extractImageFromDoc(self,docPath,docOutputPath): # text = docx2txt.process(docPath) text = docx2txt.process(docPath, docOutputPath) print(text)if __name__ == '__main__': path='C:/Users/eric/Desktop\简谱图片' dirs=os.listdir(path) fileOperate=fileUtil(); # fileOperate.deleteFiles(dirs) docPath="file/demo.docx" docOutputPath="result" fileOperate.extractImageFromDoc(docPath,docOutputPath)需要修改docx2txt 源码中的 doc2txt.py中103行的
with open(dst_fname, "w") as dst_f: dst_f.write(zipf.read(fname))改为
with open(dst_fname, "wb") as dst_f: dst_f.write(zipf.read(fname))
就可以通过运行
阅读全文
0 0
- docx2txt TypeError: write() argument must be str, not bytes
- TypeError: write() argument must be str, not bytes
- write() argument must be str, not bytes
- Python 读写文件 中文乱码 错误TypeError: write() argument must be str, not bytes+
- python提示错误TypeError: write() argument must be str, not bytes
- Python 读写文件 错误TypeError: write() argument must be str, not bytes+
- python-TypeError: write() argument must be str, not numpy.float64
- 使用pickle将对象存储到文件中时出现 TypeError: write() argument must be str, not bytes
- TypeError: must be str, not bytes
- TypeError: must be str, not bytes
- python3-网络编程-TypeError: send() argument 1 must be bytes or buffer, not str异常
- Python出现TypeError: file() argument 1 must be encoded string without NULL bytes, not str问题解决
- 关于TypeError: strptime() argument 1 must be str, not bytes解析
- 保存网页TypeError: must be str, not bytes
- Python中报错TypeError: must be str, not bytes
- TypeError: the JSON object must be str, not 'bytes'
- TypeError: expected bytes, not str
- TypeError: argument 1 must be string or buffer, not instance
- Python 3从入门到精通5-for循环
- UML详解
- swap开始使用喽
- 《Linux内核设计与实现》读书笔记(十二)- 内存管理
- 外部Toolchain编译OpenWRT<iMX6UL>
- docx2txt TypeError: write() argument must be str, not bytes
- caffe环境配置+ubuntu14.04
- pthread_join和pthread_detach的用法
- CNCC 2016 | 山世光:深度化的人脸检测与识别技术—进展与展望
- Ford-Fulkerson算法求最大流Java实现
- linux源码安装 ubuntu安装vim为例
- 单链表常见面试题(一)
- Linux 文件系统的目录
- 乱码问题!Eclipse 的控制台console必须用GBK编码。【转载】 Eclipse 的控制台必须用GBK编码。所以条件1和条件4必须同时满足否则运行的还是乱码。才能保证不是乱码。