Keeping console window open
Dave Angel
davea at ieee.org
Sun Jun 7 20:41:27 EDT 2009
Fencer wrote:
> <div class="moz-text-flowed" style="font-family: -moz-fixed">Scott
> David Daniels wrote:
>> 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.
>
> Thanks alot, this was exactly what I was looking for!
>
>>
>> --Scott David Daniels
>> Scott.Daniels at Acm.Org
>
> </div>
>
Notice also that you'd then move all the imports inside main(), rather
than putting them at outer scope. Now some imports, such as sys and os,
may want to be at outer scope, but if they don't work,. your system is
seriously busted.
More information about the Python-list
mailing list