473,772 Members | 3,603 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

General questions about embedding Python.

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 questions about python embedding:

1) Is there a good text book or other resource on embedding/extending?
(I find it hard to learn only by the tutorial and C/Python API from the
python.org site)

2) I have found that there are many ways to embedd a script:
PyEvel_EvalCode ()
PyRun_SimpleFil e()
PyObject_CallOb ject()
What are the cons and pros of using each of them?

3) Is there a problem with the PyRun_SimpleFil e(). I am trying to run
the following code:

const char *SCRIPT_NAME = "C:\\test_scrip t.py";

int _tmain(int argc, _TCHAR* argv[])
{
Py_Initialize() ;

FILE *script_file;
script_file = fopen(SCRIPT_NA ME, "r");

if (script_file != NULL)
PyRun_SimpleFil e(script_file, SCRIPT_NAME);

Py_Finalize();
return 0;
}

The python script has only one line: 'print "hello"'

I build it with Python2.3 libraries. When I try to run the code I get
access violation.

4) What is the correct way to handle/catch python exceptions in the
embedding Python code?

Forgive me if I have asked too many questions in one eMail, it is
becuase I don't really know where to start learning this subject from.

Thanks
Amit

Jul 21 '05 #1
1 1918
"amit" <am**@digitalpe ers.com> wrote:
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 questions about python embedding:


Others will probably answer your specific questions, but I will ask you
another first: Why do you (think you) need to embed python in the first
place, as opposed to wrapping the low-level performance critical C++
animation code (through SWIG, Boost, or SIP or even use Pyrex), and
have python on top ? I know very little about embedding python other
than it is not considered a pleasant experience, so make sure you look
into the alternatives and have very good reasons if you decide to go
down this route.

George

Jul 21 '05 #2

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

Similar topics

0
2515
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. The method is: 1- Create a thread for each agent (I use a pool thread, every agent run in a different thread) 2- Precompile a different script for each agent. 3- Make the agent retrieve its data
0
1849
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 explain it in details, 1. Python initialization and finalization is done in the *main* thread. 2. For each new thread I create a separate sub-interpreter . 3. Using PyRun_String("import myModule"...) before execution of python
23
2983
by: Robey Holderith | last post by:
Anyone know a good way to embed python within python? Now before you tell me that's silly, let me explain what I'd like to do. I'd like to allow user-defined scriptable objects. I'd like to give them access to modify pieces of my classes. I'd like to disallow access to pretty much the rest of the modules.
1
537
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 job like behavior rather than via the GUI (ie. I would like to run a script and see those changes reflected in the GUI as if the user had clicked buttons, etc.) The application is written in C++ and uses QT for the GUI. I have read the python...
0
1429
by: adsheehan | last post by:
Hi, I am embedding Python into a multi-threaded C++ application runnig on Solaris and need urgent clarification on the embedding architecture and its correct usage (as I am experience weird behaviors). Can anyone clarify:
0
1110
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 converting back and forth between C and Python datatypes, but my knowledge of compiling and linking is almost nonexistent. So if I could get advice on the following, it would be most appreciated. The program currently runs on Mac and Windows. 1)...
3
1365
by: Redefined Horizons | last post by:
I've got a third-part application that exposes a C API. I'd like to wrap it in Python. Is there a specific forum that covers extending and embedding Python, or are those type of questions O.K. on this list? Scott Huey
6
3008
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 interface is providing a convenient scripting toolkit for the application. One example is that a user can write a python script like: player = Player() game.loadPlayer(player) player.moveTo(location)
0
2115
by: Tim Spens | last post by:
--- On Fri, 6/27/08, Tim Spens <t_spens@yahoo.comwrote: I think I know where the problem is but I'm unsure how to fix it. When I call Register_Handler(...) from python via callback.setHandler1(callback1) this only seems to affect pythons ability to trigger an "event" in c. PyObject *Handler is always NULL even after I call Register_Handler(...). I thought there was some magic here that was assigning the pointer *Handler to my python...
0
10261
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10038
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9912
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8934
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6715
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.