I am having trouble reading a text file to a list, what I have at the moment is:
lines = open ('dracula.txt', 'r'). readlines ()
where dracula.txt is the text file in the same directory as the program, however upon running the program Python comes up with:
No such file or directory: 'dracula.txt'
I have no idea why it will not find the text file and read it to a list called lines, does anyone have any ideas?
The file name is looked up in the current working directory, which is not necessarily the same as the directory the script lives in. Try using the full path to the file, or make sure the working directory is correct. You can check the working directory py printing
os.getcwd()from inside your script (make sure youimport os).If you are on a case-sensitive file system, check the case of your file name.