[Tutor] The course of M. Gauld +a console problem

Lloyd Kvam pythontutor@venix.com
Tue Jun 10 10:48:22 2003


This is not the answer you asked for, but I was not happy with the .BAT approach.
I usually set up my console window scripts to work like this:

if __name__ == "__main__":
	import traceback
	try:
		error_code = main()	# function that does the work
	except:		# Catch ANY unhandled exception
			# we don't leave it to Python because we want to fall through
			# to the raw_input at the end
		error_code = 3	#some number that is different from main()'s numbers
		traceback.print_exc()
	if error_code:	# 0 indicates success
		print "* * * " * 10
		print "Error Message"	# whatever makes sense for your application
		print "* * * " * 10
	else:
		print "\n\nSucceeded."	# whatever makes sense for your application
	raw_input( "Press Enter Key (return) to close program")
	sys.exit( error_code)

The key piece is the raw_input statement that holds the screen open until the
enter key is pressed.  The rest just tries to make sure that errors are reported
and that the program will not exit without reaching the raw_input call.

Normally a plain "except:" statement is a mistake.  I think it is OK here.

Guillaume wrote:
> Hi,
> I found it great (I've got some problems as usually, I'll
> talk about later!)
> But I was quite astonished coz this course is not translated
> in french :-o
> So I can do it if u want (I've already translated some docs cf 
> doc.gentoofr.org)
>  
> Right my problem.
> Unfortunately at the present moment I'm working under W$ Me (beurk!)
> and when I open a .py file, this lanches the interpreter and runs the prog
> in a console window but this consol disappears immediately after the 
> prog completes
> its execution so that I can't read the output :'(
> Even when i'm using Pythonwin.
> I read that in a book (I forgot the author sorry)
> "An alternative approach is to launch the prog using a .bat file 
> containing a
> statement such as python -i helloworld.py that instructs the interpreter 
> to enter
> interactive mode after prog execution."
> Where must I put this prog? Will I have to repeat the .bat for all the
> .py file I want to read?? Or have u got a solution to make that stuff 
> easier?
> Thanx
>  
>  


-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice:	603-443-6155
fax:	801-459-9582