Tim Gordon <tim...@aleph17.co.uk> added the comment:

If you know what variable you are going to be eval-ing, or at least, 
have a list of those that might be eval-ed, you can get around this 
issue by making sure they are explicitly referenced in the inner scope 
(i.e., in the list comprehension).  For example, even though list 
comprehensions work in 2.x, generator expressions don't, but this hack 
does (on 2.4 at least):

def f():
  canBusType = 'CANdiag'
  return (eval('canBusType') for i in range(3) if True or canBusType)

By putting a semantically vacuous reference to canBusType (and any 
other variables you want) you make sure they are usable from within the 
eval as well.

----------
nosy: +QuantumTim

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue5242>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to