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.
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to