473,417 Members | 1,394 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,417 software developers and data experts.

embedded python : can't get or set a variable

Hello,

I'm trying to write a program to send python statements to a python
server via tcp and then get back results via a tcp connection. It
nearly works ... but I'm totally lost with the embedded dictionary (I'm
quite new to python).
The first part of the server start the python interpreter via
Py_Initialize() and then waits for python statements.
To send command, I get some strings and evaluate them through
PyRun_String.
To get value, I try to build a dictionary and get the result via
PyDictGetItem.
Here is a sum-up of the c++ python part:

Py_Initialize();
pDictionary = PyDict_New();

.....

PyRun_String(PyCommand.str().c_str(),Py_file_input ,pDictionary,pDictionary);

....

PyDict_SetItemString(pDictionary, "__name__", PyEval_GetBuiltins());
pResult = PyDict_GetItemString(pDictionary, "a");

....

if (!PyArg_Parse(pResult, "i", &intValue))
{
cout << "tcp-server: wrong type" << endl;
}
When I send a statement, here is a log of the messages I get :

../tcp-client 2100 send a=15
Parameter 0 : ./tcp-client
Parameter 1 : 2100
Parameter 2 : send
Parameter 3 : a=15
line to send : send a=15
tcp-client: send or stop command
Quit: tcp-client
connected to 127.0.0.1:45577
-- send a=15
send command: line = a=15
Traceback (most recent call last):
File "<string>", line 1, in ?
NameError: name 'a' is not defined
Waiting for TCP connection on port 2100 ...

When I get a statement, here is a log of the message I get:

Parameter 0 : ./tcp-client
Parameter 1 : 2100
Parameter 2 : get
Parameter 3 : a
line to send : get a
tcp-client: get command
connected to 127.0.0.1:45578
-- get a
get command - variable to get : a .
Dictionary size = 2
DEBUG: print a
print type(a )

DEBUG: pResult = 0x804fd08
DEBUG: pDictionary = 0xb7c44d74
Traceback (most recent call last):
File "<string>", line 1, in ?
NameError: name 'a' is not defined
['__builtins__', '__doc__', '__name__']
DEBUG: intValue = 15
tcp-server: get = 15
tcp-client: result = 15
Quit: tcp-client

My question is: how to get a global variables via PyDict_* ?
Why does the python interpreter prints an error message when I send my
command "a=15" ?
Why does it finally accepts my command "a=15" ?

Your sincerely,

Yann COLLETTE

Dec 26 '06 #1
0 1484

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

Similar topics

12
by: Brandon | last post by:
Java seems to have taken off as the platform and language of choice for many embedded devices. Would it be feasible for Python(perhaps running on an embedded version of Linux) to act in such a...
13
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 developer friends and am probably responsible for...
2
by: Miki Tebeka | last post by:
Hello All, I have a funny problem: An embedded python application is working fine on a "clean" computer. When it runs on a computer with python installed (the very same computer used to...
3
by: Godzilla | last post by:
Has anyone install Python on Windows XP Embedded? We wish to evaluate the possible solution of installing Python with WinXPE on a PC/104 plus module. Thank you.
20
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 install? For Linux-based embedded systems in...
7
by: wardm | last post by:
I have created a Dict object in a C++ App that calls (embedded) Python functions. The Dict is to be used to pass variable data between the C++ App and the python functions. However I cannot get...
3
by: iwl | last post by:
Hello, I would like to add Variables to my embedded python which represents variables from my C++-Programm. I found C-Api-funcs for adding my C-Funcs to python but none to add variables. I...
5
by: vishnu | last post by:
Hi there, I am embedding python 2.5 on embedded system running on RTOS where I had strict memory constraints. As python is a huge malloc intensive application, I observed huge memory...
4
by: Chris8Boyd | last post by:
I am embedding Python in a MSVC++ (2005) application. The application creates some environment and then launches a Python script that will call some functions exported from the MSVC++ application....
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.