Curious assignment behaviour

Markus Schaber markus at schabi.de
Thu Oct 11 16:13:11 EDT 2001


Hi,

Paul Rubin <phr-n2001d at nightsong.com> schrub:

> Anyway, I can live with "while x:=get_next()" instead of x=get_next.
> But I feel seriously cramped in Python when I have to say
> 
>   while 1:
>      x=get_next()
>      if not x: break
>      whatever(x)
> 
> so I hope something is done about the issue.

Using cutting-edge Python, one might wrap it with an iterator:

def seq():
  temp = get_next()
  while temp:
    yield temp
    temp = get_next()

And then easily use it this way:

for i in seq():
  whatever(x)

(this code is not tested, as I currently don't have a 2.2 python here.)

markus
-- 
You don't have to be Microsoft to suck... but it helps.
(Tim Hammerquist in comp.lang.python)



More information about the Python-list mailing list