[Python-3000] end scope of iteration variables after loop

Facundo Batista facundobatista at gmail.com
Fri Apr 18 15:15:18 CEST 2008


2008/4/18, Nicholas T <ntung at ntung.com>:

> Amaury - I think it's generally cleaner code to write
>     for myObject in someList:
>         if myObject.fits():
>            process(myObject)
>             break
> than
>    for myObject in someList:
>       if myObject.fits():
>          break
>    process(myObject)

See, I do this a lot:

  for a, b, c  in someList:
      if <some condition with a or b>:
          break
  else:
      c = foobar
  c.something()

Regards,

-- 
.    Facundo

Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org/ar/


More information about the Python-3000 mailing list