473,378 Members | 1,479 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

'psyco' problem

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.
Jul 18 '05 #1
2 1422
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
da***@dalkescientific.com
Jul 18 '05 #2
Paulo da Silva <ps*********@esotericaX.ptX> wrote in message news:<10***************@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.
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: KefX | last post by:
Hey...as for what I'm doing with Python, look at my post "Strange Hotshot problem". To make a long story short, I'm embedding Python in order to write a plugin to a freeware music program; the...
10
by: William S. Perrin | last post by:
I'm a python rookie, anyone have and suggestions to streamline this function? Thanks in advance..... def getdata(myurl): sock = urllib.urlopen(myurl) xmlSrc = sock.read() sock.close() ...
0
by: Jeremy Sanders | last post by:
Hi - I'm trying to build a Psyco rpm on Fedora 1. I try the command xpc5:~/psyco-1.1.1> python setup.py bdist_rpm this fails with: .... copying dist/psyco-1.1.1.tar.gz ->...
7
by: Ivan Voras | last post by:
I have this simple *dumb* benchmark-like program: #import psyco #psyco.full() d = 0.0 for i in xrange(1000000000): d += i print d
3
by: Dick Moores | last post by:
psyco is acting a bit psycho for me. Please see my spinForWeb.py at <http://www.rcblue.com/Python/spinForWeb.py> When psyco is in use, entering an integer somewhere between 2000 and 2500...
5
by: Fausto Arinos Barbuto | last post by:
Hi All; I have Psyco (on Windows XP) and now I want to install it on Linux, too. I FTP'd the tarball (tar.gz) from Psyco's site but can't get it compiled. First, I tried the usual "python...
6
by: danmcleran | last post by:
I'm not seeing much benefit from psyco (only 5-10% faster). Maybe this example is too trivial? Can someone give me some pointers as to what kind of code would see a dramatic benefit? Here's the...
3
by: a | last post by:
hi i tried psyco+webpy here is the error that i got please let me know if any of you has success run psyco+webpy thanks import web, psyco urls = ( '/', 'view', '/add','add'
1
by: Arash Arfaee | last post by:
Hello All, I am trying to use psyco with wingide on mac. when I open Mac Python shell I can import psyco, but not inside the wingide. Even python shell on wingide cannot import psyco. Can...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.