【发布时间】:2021-03-28 18:40:33
【问题描述】:
我遇到了“FileNotFoundError: [Errno 2] No such file or directory: 'Pronunciation_Data.txt'”的问题
我不断将我的工作目录重置到正确的位置,但它似乎不想保留(使用 Spyder/Anaconda)。我还尝试了以下方法:
file = open(r'C:\path\to\Pronunciation_Data.txt\Users\stephaniecheetham\Desktop\Thesis')
import os
os.chdir(r'C:\Users\stephaniecheetham\Desktop\Thesis')
file = open('Pronunciation_Data.txt')
file = open("Pronunciation_Data.txt",'r')
file = open("<Users/stephaniecheetham/Desktop/Thesis>\Pronunciation_Data.txt",'r')
file = open("C:/stephaniecheetham/Desktop/Thesis/Pronunciation_Data.txt",'r')
他们中的任何一个都不走运。只是同样的错误。我最近也遇到了一个模块问题,并使用import os 命令修复了它。
有什么建议吗?
【问题讨论】:
-
显而易见的答案是您在错误的目录中,或者您使用了错误的文件名。在完成
os.chdir()之后,向我们展示这个的输出:print(os.listdir())。这将向我们显示该目录中的所有文件。