Non-obvious name bindings

Kerim Borchaev warkid at storm.ru
Mon Nov 5 07:49:52 EST 2001


Hello!

  It seemed that it was my failure of understanding python but the
  fact that introducing variable in list comprehension binds it to
  functions scope(as every declaration means to?) is not really
  obvious.
  
  I mean this:
  
>>> [e for e in ['exists']]
['exists']
>>> e
'exists'

  And I'm still confused - those "temporary" variables declaration
  looks so "innocent", and in most cases (in every case for list
  comprehensions I guess?) it's everyones intension not to use this
  variable somewhere outside the loop.

  What are your thoughts?

Best regards,
 Kerim                          mailto:warkid at storm.ru






More information about the Python-list mailing list