'psyco' problem

Hannu Kankaanp?? hanzspam at yahoo.com.au
Sun Oct 10 05:57:35 EDT 2004


Paulo da Silva <psXdaXsilva at esotericaX.ptX> wrote in message news:<1097371920.617950 at mystique.esoterica.pt>...
> When running the following program:
> 
> #! /bin/env python
> # -*- coding: iso-8859-15 -*-
> 
> import psyco
> psyco.full()
> 
> def main():
>      n=eval("123+456")
>      print n
> 
> if __name__ == "__main__":
>      main()
> 
> 
> 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
>    def main():
> 579
> 
> What does this mean? Is there anything wrong?
> 
> Thank you.

It means you can't do this if main() is bound by Psyco:

def main():
    x=5
    print eval("123+x")

because as the warning message says, Psycoed eval() cannot see the
locals (x here). And it suggest that you should consider using
eval() in its two- or three-arguments form, which is described
in the Python Library Reference. So with Psyco, you might use

y = 3
def main():
    x=5
    print eval("y+x", globals(), {'x':x})

But in your case, it of course doesn't matter because in
the expression 123+456 you aren't using any locals.



More information about the Python-list mailing list