Keeping console window open

Scott David Daniels Scott.Daniels at Acm.Org
Sun Jun 7 09:26:00 EDT 2009


Tomasz Zieliński wrote:
> On 7 Cze, 14:49, Fencer <no.i.d... at want.mail.from.spammers.com> wrote:
>> My question is how can I trap
>> errors encountered by the interpreter (if that is the right way to put
>> it) in order to keep the console window open so one has a chance to see
>> the error message?
> 
> Interpreter errors are same beasts as exceptions,
> so you can try:...except: them.

To be a trifle more explicit, turn:

       ...
       if __name__ == '__main__':
          main()

into:
       ...
       if __name__ == '__main__':
          try:
              main()
          except Exception, why:
              print 'Failed:', why
              import sys, traceback
              traceback.print_tb(sys.exc_info()[2])
          raw_input('Leaving: ')

Note that building your script like this also allows you to
open the interpretter, and type:
     import mymodule
     mymodule.main()
in order to examine how it runs.

--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list