which is more 'pythonic' / 'better' ?
Jorgen Grahn
jgrahn-nntq at algonet.se
Sat Sep 17 17:57:30 EDT 2005
On Mon, 12 Sep 2005 12:52:52 +0200, gabor <gabor at nekomancer.net> wrote:
> hi,
>
> there are 2 versions of a simple code.
> which is preferred?
I don't know. Who cares?
> ===
> try:
> text = line[n]
> except IndexError:
> text = 'nothing'
> ===
>
>
> which is the one you would use?
The 'try' version. But I'd also ask myself how I could end up in a state where
this part of the code is asked to find a string that doesn't exist, and if I
really want it to keep running, with a made-up value.
/Jorgen
--
// Jorgen Grahn <jgrahn@ Ph'nglui mglw'nafh Cthulhu
\X/ algonet.se> R'lyeh wgah'nagl fhtagn!
More information about the Python-list
mailing list