[Tutor] New to python: some advises for image processing tool

Stefan Behnel stefan_ml at behnel.de
Tue Oct 13 09:09:02 CEST 2009

Nicola De Quattro wrote:
>     while(var !=q0)
>         print """
>         Please select an action from the menu below:
>         --------------------------------------
>         o) Open an image
>         +) Rotate the image of 1° clockwise
>         -) Rotate the image of -1° clockwise
>         r) Rotate the image of an input degree
>         s) Show the image
>         a) Save the image
>         q) Quit Tipsy Imp
>         --------------------------------------
>         """
>         var = raw_input("Make a choice: ");

"var" is a rather meaningless name for a variable. Something like "choice"
might be better here.

BTW, you might want to look into a GUI toolkit. There's tkinter that comes
with Python, and there are many others that aren't hard to use either.


> ------------------------------------------------
> I've some questions:
> 1) Is there a switch-case statement in Python? It seems to me not. How
> do you suggest to proceed in order to switch into var values?

Use a dict that maps characters to functions and then

	lookup_dispatch_function = { 'o' : open_image, ... }.get

	def error_fallback():
	    print("Invalid input, try again")

	# ...

        choice = raw_input("Make a choice: ")
	handle_input = lookup_dispatch_function(
                                choice.strip(), error_fallback)


More information about the Tutor mailing list