I saved a file as DictionaryE.txt in a Modules folder I created within Python. Then I type:
fh = open("DictionaryE.txt")
I get this error message:
Traceback (most recent call last):
File "<pyshell#17>", line 1, in <module>
fh = open("DictionaryE.txt")
IOError: [Errno 2] No such file or directory: 'DictionaryE.txt'
What am I doing wrong? Could someone please describe a specific, detailed step-by-step instruction on what to do? Thanks.
As other answers suggested, you need to specify the file’s path, not just the name.
For example, if you know the file is in
C:\Blah\Modules, useNote that I’ve turned the slashes “the right way up” (Unix-style;-) rather than “the Windows way”. That’s optional, but Python (and actually the underlying C runtime library) are perfectly happy with it, and it saves you trouble on many occasions (since
\, in Python string literals just as in C ones, is an “escape marker”, once in a while, if you use it, the string value you’ve actually entered is not the one you think — with ‘/’ instead, zero problems).