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
> 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
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 ag
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
--
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
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(
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 me
"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 trac
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, w
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," traceback=",
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:
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
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
* 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 someti
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
15 matches
Mail list logo