When I write Python scripts on Windows, I often write a main() function, and when it throws an exception I don't handle, the console window closes immediately before giving me a chance to look at the traceback.
The bottom of main.py usually has these 2 lines, which call the main() function when the script is started by a double-click on the .py file:
if __name__ == '__main__': main()
Replace them with:
import sys, traceback if __name__ == '__main__': try: main() except: traceback.print_exc() print >>sys.stderr print >>sys.stderr, "Press Enter to exit." blah = raw_input()
WordPress code-posting rant
In addition to what I wrote here, you should also replace any apostrophes with: '
May 11, 2007 at 7:07 pm
Strange reflex : you don’t need the ‘blah’ variable at all ;-)
May 12, 2007 at 3:36 am
That’s not quite true. There is a reason for it, and actually – you reminded me that I wanted to write a post about that.
May 12, 2007 at 4:10 am
[...] Python: Why to assign functions’ return values to dummy variables In response to Kototama’s comment in the previous post: [...]
March 23, 2008 at 2:23 pm
אתה ישראלי ? :o
March 23, 2008 at 10:19 pm
hmm. Yes