[Baypiggies] Python way to avoid usage of raise
Andrew Dalke
dalke at dalkescientific.com
Fri Oct 8 09:00:35 CEST 2010
On Oct 7, 2010, at 4:54 PM, Aahz wrote:
> ... Python uses exceptions internally for control flow that is
> NOT an error. See for example StopIteration.
But those don't need an explicit raise because they are so
easy to generate:
>>> def spam():
... yield 1
... yield 2
... iter([]).next()
... yield 3
...
>>> for i in spam():
... print i
...
1
2
>>>
In fact, this alternative is shorter
>>> len("raise StopIteration")
19
>>> len('iter([]).next()')
15
>>>
I'm definitely not saying this is a good solution!
Andrew
dalke at dalkescientific.com
More information about the Baypiggies
mailing list