Argument against iterable ints...
Alex Martelli
aleax at aleax.it
Sat Apr 6 04:55:24 EST 2002
Magnus Lie Hetland wrote:
> Just a situation that cropped up recently: While writing a little
> generator for flattening nested iterables, I used
>
> try: iter(foo)
> except: return foo
> else:
> ....
>
> (of course I could have used a for loop directly in the try clause --
> that doesn't change anything.)
It consumes the first item of foo if foo is an iterator, and thus:
try: for __ in foo: break
except: return foo
else:
...
has subtly different semantics from your code above. I agree this
does not affect your main point (on which I agree with you).
Alex
More information about the Python-list
mailing list