FileNotFoundError: [Errno 2] No such file or directory: ''
Michael F. Stemper
mstemper at gmail.com
Wed Apr 14 15:37:45 EDT 2021
On 14/04/2021 12.55, Dan Stromberg wrote:
> Open a cmd.exe, command.exe or powershell, and:
>
> cd c:\my\dir\ect\ory
> Then run your script.
>
> Or put an os.chdir(r'c:\my\dir\ect\ory') at the top of your script.
>
> Or use file = open(r'c:\my\dir\ect\ory\Egils Saga 1-15.txt', 'r')
>
> BTW, "file" means something to python other than just a variable name. You
> can replace it, as your code below (and my example above) does, but it
> obscures the thing you're replacing. That's why I like to use file_
> instead of file.
Personally, I'd use a meaningful name. For instance, I might do
saga = open(r'c:\my\dir\ect\ory\Egils Saga 1-15.txt', 'r')
or even
with open(r'c:\my\dir\ect\ory\Egils Saga 1-15.txt', 'r') as saga:
The latter form eliminates the need for saga.close(). (I'm sure that you
know that; it's directed at the OP.)
--
Michael F. Stemper
The FAQ for rec.arts.sf.written is at
<http://leepers.us/evelyn/faqs/sf-written.htm>
Please read it before posting.
More information about the Python-list
mailing list