Python 3 minor irritation
David Monaghan
monaghand.david at gmail.com
Fri Feb 5 02:43:55 EST 2010
On Thu, 04 Feb 2010 00:39:01 +0000, David Monaghan
<monaghand.david at gmail.com> wrote:
>I have a small program which reads files from the directory in which it
>resides. It's written in Python 3 and when run through IDLE or PythonWin
>works fine. If I double-click the file, it works fine in Python 2.6, but in
>3 it fails because it looks for the files to load in the Python31 folder,
>not the one the script is in.
>
>It's not a big deal, but browsing around I haven't found why the behaviour
>has been changed or any comment about it (That might be my poor search
>technique, I suppose).
>
>The program fails at:
>
> try:
> tutdoc = minidom.parse(".//Myfile.xml")
> except IOError:
> <snip>
I very much appreciate all the help offered on this, but feel a bit of an
idiot now as I can't reproduce the behaviour (it had happened on two
separate machines).
What I am still getting is a similar problem on my work computer with the
program on a network hard drive. Not always - it'll run on repeated
attempts, then fail for a few, then work again. When it failed I ran the
script as suggested:
import os
print("curdir=", os.getcwd())
print("__file__=", __file__)
input()
and got the response:
curdir= H:\
__file__= H:\FRCR\FRCR2010\Course documents\FRCR2009\Script1.py
so it's 'sticking' at H:
For interest, I ran the script from IDLE, too, and PythonWin, on three
separate computers (2 Python3, 1 Python2.6)
With that I get a NameError for __file__
curdir= H:\FRCR\FRCR2010\Course documents\FRCR2009
Traceback (most recent call last):
File "H:\FRCR\FRCR2010\Course documents\FRCR2009\Script1.py", line 3,
in <module>
print("__file__=", __file__)
NameError: name '__file__' is not defined
What have I done wrong?
DaveM
More information about the Python-list
mailing list