0

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.

eLg
  • 519
  • 4
  • 11
  • 25

2 Answers2

1

You should add folder's address to the code just like this.

f = open("E:\\python\\201607final\\names.txt","r")
James.Chao
  • 11
  • 2
0

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.

sshashank124
  • 31,495
  • 9
  • 67
  • 76