From: Gib Bogle on 4 Feb 2010 19:21 Gabriel Genellina wrote: > Sorry, I should have removed that line. This is just my setup; a normal > Python install doesn't create that registry entry. It allows Desktop > Search (or Windows Search, or whatever it is called nowadays; the F3 > key) to search inside .py files (default behavior is to just ignore > their contents). > See http://support.microsoft.com/kb/309173 > >> Is this related to the fact that when I double-click on a .py file the >> command window disappears after the execution is completed? > > (I bet the "Persistent" word confused you.) No, as you can see, it's > completely unrelated. AFAIK, there is no way (on XP and later at least) > to keep a console window open after the program exited. Three choices: > > - Open a cmd window and execute the script there. You may drag&drop the > file over the window to avoid typing the full path (I think this last > part does not work on Vista nor Win7) > > - Add a raw_input() [2.x] or input() [3.x] line at the end of the script > > - Rename it with a '.cmd' extension and add this line at the very top: > > @(C:\Python26\Python -x %~f0 %* || pause) && goto:EOF > > (see this post by Duncan Booth last month: > http://comments.gmane.org/gmane.comp.python.general/650913 ) > Thanks Gabriel. I didn't know about the drag&drop capability (learn something every day, forget two things). BTW input() works for me in 2.5. Cheers Gib
From: David Monaghan on 5 Feb 2010 02:43
On Thu, 04 Feb 2010 00:39:01 +0000, David Monaghan <monaghand.david(a)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 |