首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用CON文件拆分数据库抛出errno 9错误文件描述符

用CON文件拆分数据库抛出errno 9错误文件描述符
EN

Stack Overflow用户
提问于 2014-04-24 10:16:30
回答 1查看 103关注 0票数 0

我做了一些研究,据我所知,这通常发生在文件在结束使用之前关闭时?

但这对这里发生的事情毫无意义。

这是我的代码:

代码语言:javascript
复制
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“,就会发生错误:

代码语言:javascript
复制
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中文件的保留名称,以及其他一些文件,因此需要用其他的名称来替换。请在此查询更多细节。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-24 11:35:23

自答

CON是windows中文件的保留名称,以及其他一些文件,因此需要用其他的名称来替换。请在此查询更多细节。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23266035

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档