who is simpler? try/except/else or try/except

Fabio Z Tessitore fabioztessitore at libero.it
Sun Aug 12 13:16:36 EDT 2007


Hi all,

reading Dive Into Python, on Chapter 6 (exception), I've found:

"This code comes from the getpass module, a wrapper module for getting a 
password from the user"

try:
	import termios, TERMIOS
except ImportError:
	try:
		import msvcrt
	except ImportError:
		try:
			from EasyDialogs import AskPassword
		except ImportError:
			getpass = default_getpass
		else:
			getpass = AskPassword
	else:
		getpass = win_getpass
else:
	getpass = unix_getpass

Knowing that this code is very simple, my question is about simplicity. I 
think it is simpler the following code. I haven't a long experience on 
Python, so I'd like to know your opinions about.

try:
	import termios, TERMIOS
	getpass = unix_getpass

except ImportError:
	try:
		import msvcrt
		getpass = win_getpass

	except ImportError:
		try:
			from EasyDialogs import AskPassword
			getpass = AskPassword

		except ImportError:
			getpass = default_getpass

thanks,
Fabio



More information about the Python-list mailing list