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

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_SimpleFile()
PyObject_CallObject()
What are the cons and pros of using each of them?

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

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

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

FILE *script_file;
script_file = fopen(SCRIPT_NAME, "r");

if (script_file != NULL)
PyRun_SimpleFile(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 1878
"amit" <am**@digitalpeers.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
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...
23
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...
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...
0
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...
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...
3
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...
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...
0
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...

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.