python读取文件遇到问题及解决
2024-08-24 20:51:52
用python的open()函数打开文件时,
1、文件写绝对路径报IOError: [Errno 2] No such file or directory。文件改为相对路径(只写文件名)解决该问题
2、文件是docx类型,如下代码执行时报TypeError: file() takes at most 3 arguments (4 given)path = r'file2.docx#ignore 忽略错误
path = r'file2.docx'
#ignore 忽略错误
f = open(path, 'r',encoding = 'utf-8',errors = 'ignore'
引入io模块,解决该问题,代码如下:
import io
path = r'file2.docx'
#ignore 忽略错误
f = io.open(path, 'r',encoding = 'utf-8',errors = 'ignore')
最新文章
- asp.net[web.config] httphandlers 与实现自由定义访问地址
- js去掉html标签和去掉字符串文本的所有的空格
- 射击比赛 (POJ 1719) 题解
- outlook配置
- C# DataGridView的初始化
- Delphi中DLL的其他应用
- Excel中将时间格式转化成时间戳格式
- PLSQL连接Oracle数据库,使用instantclient_10_2客户端
- struts2 DMI问题
- PHP 11:函数
- Docker 搭建 etcd 集群及管理
- 总结两种动态代理jdk代理和cglib代理
- 第二篇:数据可视化 - 基本API
- [转] 分代垃圾回收的 新旧代引用问题(原标题:Back To Basics: Generational Garbage Collection)
- node webpack4.6简单配置
- 【BZOJ2159】Crash的文明世界
- sql 存储过程命名规范
- mysql自动创建分区
- Redis 缓存服务配置与使用
- hightcharts 如何修改legend图例的样式
热门文章
- 搜索引擎学习(六)Query的子类查询
- Oracle学习(五)DBLINK
- google chrome安装非官方市场插件方法
- websocket+sockjs+stompjs详解及实例
- mysql-1-select
- 软件定义网络实验记录①--Mininet 源码安装和可视化拓扑工具
- VS2013 C++ 生成与调用DLL(动态链接库) 需要验证
- Eclipse 重命名工程、包、类
- 实现Excel文件的上传和解析
- Avoid mutating a prop directly since the value will be overwritten whenever the parent component re