2015-11-04 266 views
-4

我有一个txt文件,如果我尝试打开它蟒蛇说:文件TXT:FileNotFoundError:[错误2]没有这样的文件或目录

runfile('/Users/costanzanaldi/Desktop/tesi/Tesi_Naldi/COdice _Python/untitled0.py', wdir='/Users/costanzanaldi/Desktop/tesi/Tesi_Naldi/COdice _Python') 

Traceback (most recent call last): 

    File "<ipython-input-30-b4bdfdd17ca2>", line 1, in <module> 
    runfile('/Users/costanzanaldi/Desktop/tesi/Tesi_Naldi/COdice _Python/untitled0.py', wdir='/Users/costanzanaldi/Desktop/tesi/Tesi_Naldi/COdice _Python') 

    File "/Users/costanzanaldi/anaconda/lib/python3.4/site-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 685, in runfile 
    execfile(filename, namespace) 

    File "/Users/costanzanaldi/anaconda/lib/python3.4/site-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 85, in execfile 
    exec(compile(open(filename, 'rb').read(), filename, 'exec'), namespace) 

    File "/Users/costanzanaldi/Desktop/tesi/Tesi_Naldi/COdice _Python/untitled0.py", line 13, in <module> 
    in_file = open("POLO_SCIENTIFICO_(LAMMA).txt","r") 

FileNotFoundError: [Errno 2] No such file or directory: 'POLO_SCIENTIFICO_(LAMMA).txt' 

1)该文件存在! 2)路径正确!它在桌面上!

回答

1

您需要将您的目录更改为桌面才能访问该文件。你会怎么做,使用os模块,像这样:

import os 
os.chdir("/path/to/Desktop") 
+0

我这样做了,但输出是stille错误.. – costanza

0

据推测,这意味着该文件是不是在桌面上。 (我假设您将Ethan的“/ path/to/Desktop”更改为系统中的正确路径,即“/ Users/costanzanaldi/Desktop”?)。无论你在哪里,都需要打开()完整路径到POLO_SCIENTIFICO_(LAMMA).txt,除非你有正确的目录chdir。我假设你已经在POLO_SCIENTIFICO_(LAMMA).txt中得到了正确的字母大小写:-)

相关问题