簡體   English   中英

使用CON文件拆分引發errno 9錯誤的文件描述符的數據庫

[英]Splitting database throwing errno 9 bad file descriptor with CON file

我已經進行了一些研究,從中我可以看出這通常是在文件使用完畢之前關閉的嗎?

但這對於這里發生的事情沒有意義。

這是我的代碼:

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文件。 乍一看似乎沒問題(有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中其他文件的保留名稱,因此需要用其他名稱替換。 在此處查看更多詳細信息

自我回答

CON是Windows中其他文件的保留名稱,因此需要用其他名稱替換。 在此處查看更多詳細信息

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM