while expression feature proposal
Paul Rubin
no.email at nospam.invalid
Wed Oct 24 18:19:14 EDT 2012
Dan Loewenherz <dloewenherz at gmail.com> writes:
> VAR = EXPR
> while VAR:
> BLOCK
> VAR = EXPR
for VAR in iter(lambda: EXPR, None):
BLOCK
where the termination sentinel might be False or '' or whatever instead
of None. Of course if EXPR is a callable, there's no lambda.
> while EXPR as VAR:
> BLOCK
This is kind of nice. I wonder if it could generalize "with" somehow,
i.e. use the context manager for EXPR if it has one. Or maybe "iter"
could be generalized so you could pass an arbutrary predicate as
termination condition, instead of a single sentinel value.
More information about the Python-list
mailing list