[Tutor] more about how I overcame not being able to run my programs

Steven D'Aprano steve at pearwood.info
Fri Mar 16 01:35:35 CET 2012


Alan Gauld wrote:
> On 15/03/12 22:39, Tamar Osher wrote:
> 
>> try:
>> import os
>> # my program
>> finally:
>> input ('\n\t\t\tPress the enter key to continue.')
>> os.system ('pause')
> 
> It's more conventional to put the import at the very top, before the 
> try: line.

True, but in this case, if there is an import error, the message will flash by 
without being read. Wrapping the *entire* program, imports and all, ensures 
that the program will pause regardless of what happens.


-- 
Steven



More information about the Tutor mailing list