[Tutor] Please critique my Fraq.py (original) (raw)

Brian van den Broek bvande at po-box.mcgill.ca
Sun Jul 25 12:49:46 CEST 2004


Dick Moores said unto the world upon 25/07/2004 06:20:

At 02:44 7/25/2004, Brian van den Broek wrote:

"" At two points in the inner loop I've got a break. But I need another at the end of the outer loop to get out smoothly. Thanks, Dick Moores

Hi Dick, I haven't followed your thread closely so I don't recall your program. Thus, it might not meet your definition of "smooth" in the case at hand, but have you tried sys.exit() ? Brian, Yes! I modified that silly test/game script to:

Until yesterday, when tutors taught me the wonders of the Win XP command line, I was testing scripts only on IDLE. On IDLE, sys.exit() employed as above gets a big red Traceback (most recent call last): File "C:/Python23/DumbTest2.py", line 10, in -toplevel- sys.exit() SystemExit Executing via the command line gets a smooth quit. This is the second time in a couple of weeks that IDLE has failed to execute code correctly. The first was when I was trying to use msvcrt.getch(). Whew! Guess I should stick just with the command line for execution of scripts from now on. Thanks, Dick

Hi Dick,

glad that helped :-)

I don't know much about msvcrt.getch(). But for sys.exit(), I don't think it is right the IDLE is dong it 'wrong'.

IDLE is configured to display all exceptions in the interactive window. sys.exit() ends programs by raising the SystemExit exception, and IDLE displays it, as it should with exceptions.

IDLE could be coded to let SystemExit exceptions silently terminate your script. But I think that in a more complicated case than your program this could make it harder for you to figure out why your program terminated. Worse yet, imagine you imported a package and hadn't read the source (or couldn't if it was in C and like me, you can't make use of C-source yet). If it raised a SystemExit and IDLE didn't tell you, you'd have quite a puzzle working out why your script stopped. With the exception, you at least have a better starting point than "it stopped. I wonder why?" ;-) (import this #2).

Also, since it is a Tkinter program, you shouldn't run Tkinter scripts via IDLE -- IDLE can't sort out which Tkinter things are meant for it and which for your script.

Best,

Brian vdB



More information about the Tutor mailing list