which is more 'pythonic' / 'better' ?

gabor gabor at nekomancer.net
Mon Sep 12 06:52:52 EDT 2005


hi,

there are 2 versions of a simple code.
which is preferred?


===
if len(line) >= (n+1):
	text = line[n]
else:
	text = 'nothing'
===


===
try:
	text = line[n]
except IndexError:
	text = 'nothing'
===


which is the one you would use?

thanks,
gabor



More information about the Python-list mailing list