'psyco' problem

Andrew Dalke adalke at mindspring.com
Sun Oct 10 05:20:35 CEST 2004


Paulo da Silva wrote:
 > I got:
 > ../tp.py:7: warning: eval()/execfile() cannot see the locals in functions
 > bound by Psyco; consider using eval() in its two- or three-arguments form

In the following

   def main():
       n=eval("123+456")
       print n

it appears that Psycho can't peer into the eval string
to figure out what's used.  It doesn't know, for example,
if you're trying to do something like this

   import math
   def main():
       n = 0
       n=eval("123+n*math.pi")
       print n

To handle it correctly it would need to understand
Python's full scopes, which is hard.

Instead, Psyco is asking you for some help.  You
need to tell it what variables might be used inside
the eval string by passing the list of possible
values via the optional 2nd and 3rd arguments to
eval.  See the docs for details.  Here's how to make
what you want work

   def main():
       n=eval("123+456", {})
       print n

WARNING: this is based solely on reading the error
message.  My primary machine is a Mac and Psyco
doesn't run on it so I cannot test my answer.

				Andrew
				dalke at dalkescientific.com



More information about the Python-list mailing list