ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> activepython
activepython
Re: keep console window after double-click foo.py
by Fra Mue other posts by this author
Mar 22 2007 7:29PM messages near this date
view in the new Beta List Site
keep console window after double-click foo.py | Re: keep console window after double-click foo.py
Hi Steve,

take a look at part 8.3 Handling Exceptions of the Python tutorial. It 
states:
"The try ... except statement has an optional /else clause/, which, when 
present, must follow all except clauses. It is useful for code that must 
be executed if the try clause *does not* raise an exception."

Take a look at your code, now. If main raises any exception, it is 
reraised and never handled. Furthermore the else clause is never 
executed. I think the following piece of code demonstrates pretty clear 
what happens:

import sys

def main():
    print "In function main."
    #raise

try:
    main()
except:
    print "Exception catched in __main__"
    raw_input("Please press Enter to quit")
else:
    print "In else-clause of try-except-else clause"
    print "Press RETURN to exit..."
    sys.stdin.readline()

Save it in a file and double click on it. The window remains open and 
you will get the following output:

In function main.
In else-clause of try-except-else clause
Press RETURN to exit...

Uncomment the raise statement in function main. Double click, again. The 
window remains open and you get the following output:

In function main.
Exception catched in __main__
Please press Enter to quit

HTH
Frank


smr@[...].ca schrieb:
>  Howdy,
> 
>  I installed Active State Python, and wrote a simple script, say
>  'foo.py'.  If I double-click on 'foo.py' from the windows explorer, a
>  console window opens, the script executes, and the window closes
>  again.
> 
>  I'd like the window to stick around if there are any exceptions
>  raised.  I tried to put all my code in function main() and use
> 
>  try:
>      main()
>  except None:
>      raise
>  else:
>      print "Press RETURN to exit..."
>      sys.stdin.readline()
> 
> 
>  No dice: the window closes even if main() raises an exception.  
>  Any idea how to do it?
> 
>  Thanks,
>  -Steve
> 
>  _______________________________________________
>  ActivePython mailing list
>  ActivePython@[...].com
>  To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>  Other options: http://listserv.ActiveState.com/mailman/listinfo/ActivePython
> 
> 
>    
_______________________________________________
ActivePython mailing list
ActivePython@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Other options: http://listserv.ActiveState.com/mailman/listinfo/ActivePython
Thread:
smr
Fra Mue
Trent Mick
smr

Privacy Policy | Email Opt-out | Feedback | Syndication
© 2004 ActiveState, a division of Sophos All rights reserved