使用xlsxwriter写文件时,遇到以下报错
Traceback (most recent call last):
File "D:\python\lib\site-packages\xlsxwriter\workbook.py", line 324, in close
self._store_workbook()
File "D:\python\lib\site-packages\xlsxwriter\workbook.py", line 659, in _store_workbook
raise e
File "D:\python\lib\site-packages\xlsxwriter\workbook.py", line 656, in _store_workbook
xlsx_file = ZipFile(self.filename, "w", compression=ZIP_DEFLATED,
File "D:\python\lib\zipfile.py", line 1249, in __init__
self.fp = io.open(file, filemode)
PermissionError: [Errno 13] Permission denied: 'D:\\888\\8\\8a\\name.xlsx'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "d:\888\8\8a\88\information from txt to excel", line 42, in <module>
wb.close()
File "D:\python\lib\site-packages\xlsxwriter\workbook.py", line 326, in close
raise FileCreateError(e)
xlsxwriter.exceptions.FileCreateError: [Errno 13] Permission denied: 'D:\\888\\8\\8a\\name.xlsx'
原因可能是因为打开了之前写的excel文件,没有关闭。
打开txt以及写excel文件时遇到以下报错
xlsxwriter.exceptions.FileCreateError: [Errno 22] Invalid argument: 'D:\\888\\8\\8a\x0culltext_huizong.xlsx'
OSError: [Errno 22] Invalid argument: 'D:\\888\\8\\8a\x0cull_text_huizong.txt'
经过搜索,暂定可能的原因是文件名首字母为f与前面的斜杠被识别为特殊符号,以至于python无法找到指定文件,建议避免首字母使用f、n、t等,或者按照下述的方法
在路径前面加r,如下
f = open(r'D:\888\8\8a\full_text_huizong.txt','r',encoding='utf-8-sig')
使用“/”、“\\”或“//”来代替“\”
f = open(r'D:/888/8/8a/full_text_huizong.txt','r',encoding='utf-8-sig')
f = open(r'D://888//8//8a//full_text_huizong.txt','r',encoding='utf-8-sig')
f = open('D:\\888\\8\\8a\\full_text_huizong.txt','r',encoding='utf-8-sig')