用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')