Re: Windows Cmd.exe Window

2005-07-08 Thread Peter Herndon
Giles, you keep mentioning syntax errors as the (/a) cause of the problem. I suggest you avoid such problems, so that the import sethook approach, et al. will actually work. The easiest thing to do is to run PyChecker on your script prior to executing it. PyChecker will catch your syntax errors

Windows Cmd.exe Window

2005-07-07 Thread Giles Brown
For my sins I'm a MS Windows user at work and apart from that I have a small problem ... I like to write python scripts to do small tasks and then double click on them from the file explorer to run them. Unfortunately I'm not perfect and sometimes I make mistakes and have unhandled exceptions or

Re: Windows Cmd.exe Window

2005-07-07 Thread Thorsten Kampe
* Giles Brown (2005-07-07 13:56 +0100) For my sins I'm a MS Windows user at work and apart from that I have a small problem ... I like to write python scripts to do small tasks and then double click on them from the file explorer to run them. Unfortunately I'm not perfect and sometimes I

Re: Windows Cmd.exe Window

2005-07-07 Thread Giles Brown
Nah. You're missing my point. I only want the command window not to be closed if there is an *exception*. Picky I know, but there you go. Giles -- http://mail.python.org/mailman/listinfo/python-list

Re: Windows Cmd.exe Window

2005-07-07 Thread harold fellermann
On 07.07.2005, at 15:25, Giles Brown wrote: Nah. You're missing my point. I only want the command window not to be closed if there is an *exception*. Picky I know, but there you go. well, then register raw_input as exit function: import atexit atexit.register(raw_input) works fine in

Re: Windows Cmd.exe Window

2005-07-07 Thread harold fellermann
On 07.07.2005, at 15:43, harold fellermann wrote: On 07.07.2005, at 15:25, Giles Brown wrote: Nah. You're missing my point. I only want the command window not to be closed if there is an *exception*. Picky I know, but there you go. well, then register raw_input as exit function:

Re: Windows Cmd.exe Window

2005-07-07 Thread Larry Bates
Use sys.excepthook to hook a function you define and in that function print a traceback and pause before exiting. Something like (not tested but copied from working example): import sys def Myexcepthook(type, value, traceback): print in Myexcepthook-type=, type, value=,value,

Re: Windows Cmd.exe Window

2005-07-07 Thread Giles Brown
Thanks for your replies. I think we might have a miscommunication here as (to my understanding) neither of your replies actually solve my problem. After all, the function raw_input is just another way of blocking until user input. I was already doing that using os.system('pause'). To recap,

Re: Windows Cmd.exe Window

2005-07-07 Thread Thomas Heller
Giles Brown [EMAIL PROTECTED] writes: Nah. You're missing my point. I only want the command window not to be closed if there is an *exception*. Picky I know, but there you go. I find it useful to set an sys.excepthook which calls the debugger pdb.pm(). This way I not only see the

Re: Windows Cmd.exe Window

2005-07-07 Thread Giles Brown
Hi Larry, I mentioned how I am already using sys.excepthook in my initial posting. What I'm looking for is: 1) Is there any better way of solving the problem than setting sys.excepthook in sitecustomize.py? 2) Or is there a better way of detecting when I am running a .cmd based script than the

Re: Windows Cmd.exe Window

2005-07-07 Thread Duncan Booth
harold fellermann wrote: sorry, I did not think. if you want to wait for input _only_ if an exception occured, your exit function needs to check for the exception: import atexit def wait_on_exc() : ... import sys ... if sys.exc_type : ... raw_input() ...

Re: Windows Cmd.exe Window

2005-07-07 Thread Duncan Booth
Giles Brown wrote: The special first line is: @pythoncmd -x %~f0 %* exit /b (In the python.org FAQ for windows it says @setlocal enableextensions python -x %~f0 %* goto :EOF but since I have no idea which is right I chose the simpler looking one) This approach does require

Re: Windows Cmd.exe Window

2005-07-07 Thread Giles Brown
Hooray! We have a winner! Thanks Duncan. Your improved shell line will do the job very nicely. :) (btw, the problem with import sethook at the top of the script is that syntax errors in the top-level will prevent the import from being run meaning we don't get our traceback anymore.) Giles --

Re: Windows Cmd.exe Window

2005-07-07 Thread Giles Brown
Addendum - forgot to mention that the problem with checking the extension of sys.argv[0] is that sys.argv[0] is not set until after sitecustomize.py is run (and it needs to be in sitecustomize.py not an imported module due to the top-level SyntaxError problem mentioned in my other post). Cheers

Re: Windows Cmd.exe Window

2005-07-07 Thread [EMAIL PROTECTED]
In the past I have created .bat wrapper files that just call the python interpreter, but it is a bit tedious to have to create a matching .bat file for every script. So I came up with the following approach... I frequently use a batch file wrapper. Typically it has a long friendly name