Conditional Expressions don't solve the problem
Dale Strickland-Clark
dale at riverhall.NOTHANKS.co.uk
Wed Oct 17 04:36:41 EDT 2001
Guido van Rossum <guido at python.org> wrote:
>It comes from the analogy between
>
> while <expr>:
> <code>
> else:
> <code>
>
>and
>
> if <expr>:
> <code>
> else:
> <code>
>
>In both cases, when <expr> is false, a jump to the else: label is
>taken.
>
>From this it also follows that the else part of a loop is skipped when
>a break is taken -- hence finally would be wrong.
OK. Fair enough.
>
>> Is iter just an extra object layer to map the interface. Will it be an
>> overhead?
>
>What do you mean?
Well, I could knock up an iter of my own:
class iter:
def __init__(self, function, endCase):
self.endCase = endCase
self.function = function
def __getitem__(self, v):
r = self.function()
if r == self.endCase:
raise IndexError
return r
But this would add an extra layer of Python between a function and
where it is used.
On our larger systems, I would prefer not to introduce such overheads
where it is only a small coding convenience.
Is iter handled more effeciently than this?
--
Dale Strickland-Clark
Riverhall Systems Ltd
More information about the Python-list
mailing list