Hi,

The following example demonstrates the variable 'v' used in the list
comprehension is accessible out site the list comprehension.

I think that 'v' should be strictly local. Does anybody know where
this behavior is documented and why it is designed this way?

~/linux/test/python/man/library/__buildin__/class/{/iteritems$ cat main1.py
#!/usr/bin/env python

d = {'one': 10, 'two': 20}

for k, v in d.iteritems():
  print k, v
  x=[2*v for v in [1, 2, 3]]
  print x
  print k, v
~/linux/test/python/man/library/__buildin__/class/{/iteritems$ ./main1.py
two 20
[2, 4, 6]
two 3
one 10
[2, 4, 6]
one 3


-- 
Regards,
Peng
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to