By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,715 Members | 748 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,715 IT Pros & Developers. It's quick & easy.

General questions about embedding Python.

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
"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 discussion thread is closed

Replies have been disabled for this discussion.