473,407 Members | 2,359 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,407 software developers and data experts.

questions on python script compiling for embedding

Dear all,

I am trying to embed python into another scripting language, to do this
I need to solve a number of problems on importing or compiling python
script. First let me state what exactly I want to do, that is, I want
the following syntax to be supported in the host language which I am
developing:

################################################## ####
# scripts in the host language

routine Test()
do
println("printed by Test()");
end

global astring = "ASTRING";

# begin python scripts:
@begin(python)

def PyTest( s ):
print s
return 1000;

# access global variables from the host scripts
pystring = astring;

# call function defined in the host script:
Test();

@end(python)

# call a python function:
n = PyTest( "invoke python function" );

################################################## ####

So there are the following problems come out naturally:

#1. can I compile a block of python script to get the list of
variables, classes and functions etc. (or at least the names) without
executing?

Because I need the host script to see the python definitions.

The Py_CompileStringFlags() seems to do the work. But it returns a code
object, which I don't know exactly and if it is possible to get the
list of variables, classes and functions from this kind of object.

##2. Can I pass a list global variables for such compiling?

Because I need python scripts also see the variables functions etc.
defined in the host scripts.

*********
For these two problem, a C API like this would be pefect:
PyObject* Py_CompileStringFlagsXXX( const char *str, const char *file,
int start, PyObject *module, PyCompilerFlags *flags );

Different from Py_CompileStringFlags(), this function should take
another parameter (Python module object), which serve as a
**namespace**, to solve undefined names in the souce "str", and store
global variables, functions and classes etc defined in this source
string.

So the third question is:

###3. Is there some way, or how to do such thing as
Py_CompileStringFlagsXXX() would do???

Of course, I do not expect such API should be added soon or even added.

Thanks a lot,

Limin

May 17 '06 #1
0 1437

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

Similar topics

0
by: jordi | last post by:
Hi, I'm starting to use Python embedded in a C program. I'm using Python to execute several scripts using as a variables information retrieved for several multithread "agents" written in C. ...
0
by: Atul Kshirsagar | last post by:
I am embedding python in my C++ application. I am using Python *2.3.2* with a C++ extention DLL in multi-threaded environment. I am using SWIG-1.3.19 to generate C++ to Python interface. Now to...
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...
1
by: Martin | last post by:
Greetings, I am new to python and wish to embed python in an 3D graphics application to provide application automation. The high level goal is to be able to drive my app from a script for batch...
1
by: amit | last post by:
Hello, I am currently studying how to embedd python. I am developing a graphical C++ application. My goal is to embedd python script that will control some kind of animation. I have some...
0
by: Kenneth McDonald | last post by:
We're looking at embedding Python into our product to provide users with the ability to write scripts for the programming. My knowledge of Python is excellent, I'm familiar with the concepts of...
8
by: Brennus | last post by:
I have a dll/so which embeds python. I can verify it works by compiling it as an executable and adding an appropriate main. I tried to write unit tests for this library with ctypes and a simple...
6
by: Qun Cao | last post by:
Hi Everyone, I am a beginner on cross language development. My problem at hand is to build a python interface for a C++ application built on top of a 3D game engine. The purpose of this python...
4
by: Julian | last post by:
Hi, first of all, I have to say I am new to Python. I have been working with a finite element analysis program written in c++. now, I am trying to 'rebuild' this code (possibly a full re-write)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.