eLg eLg - 2 months ago 9x
Python Question

Python: [Errno 2] No such file or directory: 'lines.txt'

I have the python tool on Visual Studio 2010.
I tried to open a text file, which is in the same folder with the .py file, but I am having

[Errno 2] No such file or directory: 'lines.txt'

Here is the line:

fh = open('lines.txt')

please help.


There is your problem, if you're going to run the script as C:\folder\folder\script.py, then your code will try to look for input.txt in C:. You should first navigate to the folder and then run the script simply as script.py or python script.py.