472,325 Members | 1,002 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

AttributeError with embedded Python

I've embedded Python in an extension for a program we are using here
at work. And I'm a bit stumped as to why I am getting an
AttributeError only in the embedded Python.

First, a bit of what I am doing. We use a simulator for a
microprocessor we are using in our systems. Our simulator allows for
extensions that can be loaded as shared libraries. Rather than code
the entire extension in C/C++, I would like to make use of Python to
script the extension.

So, I first initialize Python (examples below leave out the error
checking, but it is there):


And then I make sure the script directory is in the path with
Py_GetPath() and PySys_SetPath().

Finally, I import the script (say it is in a local file 'script.py'):

pName = PyString_FromString("script");
pModule = PyImport_Import(pName);

Once the module is imported, I get objects to the functions in the
script I want to call later, which I do with:

pName = PyString_FromString("foo");
pFunc = PyObject_GetAttr(pModule, pName);

Later, I come back and call the function:

pResult = PyObject_CallObject(pFunc, NULL);

And it always fails whenever I iterate of a list. Say for example my
Python function is:

def foo():
a = ['cat', 'window', 'defenstrate']
for x in a:
print x, len(x)

Now, the function runs, i.e. I see the output ("cat 3\nwindow
6\ndefenstrate 11\n"), but I always get the following error message:

Traceback (most recent call last):
File "./script.py", line 3, in foo
for x in a:
AttributeError: 'module' object has no attribute 'reset'

Now, if I run this exact same script using Python standalone, i.e.:

Python 2.3.4 (#1, Nov 20 2007, 15:18:15)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>import script
cat 3
window 6
defenstrate 11
(I know, and old version of Python. But we are stuck with it because
our processes require us to validate a newer version if we change.)

This works great. What is the difference? Why does it work in one
context but not the other?

Jul 1 '08 #1
0 934

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

Similar topics

by: seth | last post by:
Last week I encountered an AttributeError in my unit tests that I wasn'table to catch with an "except AttributeError" statement. The problem...
by: Reinhard Koenig | last post by:
Hello, I' m using Python 2.3, win32all-157 under W2K. I've applied the makepy utility for the Word 8.0 object library. I now receive: Python...
by: GrelEns | last post by:
hello, i would like if this behaviour can be obtained from python : trap an attributeError from inside a subclassing dict class... (here is a...
by: Alexander May | last post by:
Hi, I love Python! I've been using it for a couple of years now and have found it to be a highly productive language. I evangelize it to my...
by: Jack | last post by:
Is there a Python packaging that is specifically for embedded systems? ie, very small and configurable so the user gets to select what modules to...
by: rsd | last post by:
Hi, I'm trying get Samsung YH-920 mp3 player to work with Debian GNU/Linux. To do that I need to run...
by: noroi | last post by:
Hi, I got problems while running Eric Blossom's FM receiver's example codes from the GNURadio tutorial page; the RF front end reads the signal...
by: Nikhil | last post by:
I have recently written a small module. When I import the module, I always get the error only when I do -- Traceback (most recent call...
by: Peter LaDow | last post by:
I posted this on c.l.p, but with the high level of traffic there, I thought I'd try to post here as well. I've embedded Python in an extension...
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

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.