我在 Python 中遇到了一个我无法掌握的 IOError。我有一个相对简单的脚本来检索各种科学文章并将它们组织成一个目录结构。
编写每个输出文件的调用在这里(在 for-each 循环中):
(58) outfile = open(curr_dir + "/" + article + ".txt",'w')
(59) outfile.write("title: " + title + '\n')
(60) outfile.write("abstract: " + abstract + '\n')
(61) outfile.close()
对于一千多篇文章,输出文件可以毫无问题地打开和编写。但是,在两个上,它失败,以下 IOError 指向上面显示的第一行:
Traceback (most recent call last):
File "script.py", line 58, in <module>
outfile = open(curr_dir + "/" + article + ".txt",'w')
IOError: [Errno 2] No such file or directory: '/path/to/file/text.html.txt'
这是两个文件:
/path/2-minute-not-invasive-screening-for-cardio-vascular-diseases-relative-limitation-of-c-reactive-protein-compared-with-more-sensitive-l-homocystine-as-cardio-vascular-risk-factors-safe-and-effective-treatment-using-the-selective-drug-uptake-enhancementme.html.txt
/path/expression-of-chemokine-receptors-i-immunohistochemical-analyses-with-new-monoclonal-antibodies-from-the-8th-iifferentiation-antigens.html.txt
据我所知,所有其他 1000 多个文档看起来或多或少相同。例如,其他文档以数字开头,并且在打印时打开它们没有问题。此外,这些文章正试图写入其他文章已经打印过的同一目录。我会怀疑第一种情况的长度,但第二种情况可能不是问题。
有什么我想念的吗?谢谢您的帮助!