我做了一些研究,据我所知,这通常发生在文件在结束使用之前关闭时?
但这对这里发生的事情毫无意义。
这是我的代码:
import csv
dicto = {}
name = ""
with open(input("enter filepath here: "), "r") as mainfile:
reader = csv.reader(mainfile)
for row in reader:
name = row[8].lstrip("'")
name = name.lstrip("\xa0")
name1 = name
name = name.upper()
if not name[:3] in dicto:
dicto[name[:3]] = [name[:3]+".js", 0]
with open(dicto[name[:3]][0], "w") as file1: #here is the problem line
file1.write("tags=[")
else:
dicto[name[:3]][1] += 1
if name[:1] == "#":
print(name)
with open(dicto[name[:3]][0], "a") as file2:
if dicto[name[:3]][1]>0:
file2.write('various spam')
else:
file2.write('various eggs')
for key in dicto.keys():
with open(dicto[key][0], "a") as file3:
file3.write("\n];")我正在运行一个大型数据库,并将其拆分为JS文件,这些文件以数据标签的前三个字母命名。它似乎在一开始运行ok (有44k项要通过,所以它需要几秒钟完成)。总的来说,我目前已经生成了309个文件,尽管没有一个文件是完整的。但是,一旦到达组合体"CON“,就会发生错误:
Traceback (most recent call last):
File "C:\Users\SarbickiN\Documents\Codes\Python\schools\schools.py", line 16, in <module>
with open(dicto[name[:3]][0], "w") as file1:
OSError: [Errno 9] Bad file descriptor: 'CON.js'这就关闭了节目。有什么原因会这样吗?我在引起这一问题的台词旁边发表了一条评论。
编辑:解决方案(或缺乏解决方案)
CON是windows中文件的保留名称,以及其他一些文件,因此需要用其他的名称来替换。请在此查询更多细节。。
发布于 2014-04-24 11:35:23
自答
CON是windows中文件的保留名称,以及其他一些文件,因此需要用其他的名称来替换。请在此查询更多细节。。
https://stackoverflow.com/questions/23266035
复制相似问题