This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author QuantumTim
Recipients JiafeiPeng, QuantumTim, ezio.melotti, georg.brandl, hagen
Date 2009-02-13.13:01:03
SpamBayes Score 4.057807e-10
Marked as misclassified No
Message-id <1234530066.22.0.758765755892.issue5242@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2009-02-13 13:01:06QuantumTimsetrecipients: + QuantumTim, georg.brandl, ezio.melotti, hagen, JiafeiPeng
2009-02-13 13:01:06QuantumTimsetmessageid: <1234530066.22.0.758765755892.issue5242@psf.upfronthosting.co.za>
2009-02-13 13:01:04QuantumTimlinkissue5242 messages
2009-02-13 13:01:03QuantumTimcreate