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

Embedding Python question.

Dear all,

I've successfully embedded the Python interpreter into a set of C/C++
application programs that use a larger library project with information
from http://docs.python.org/api/api.html and
http://docs.python.org/ext/ext.html. Now I want to wrap classes and
functions from the associated libraries so that I can write new
applications completely in Python, but I'm not entirely sure how to
start because I have some problems understanding which is the best way.
It would be nice if someone could answer the following questions and
clarify this matter:

- until now I've used the approach as documented in
http://docs.python.org/ext/extending...embedding.html to extend the
embedded interpreter and that works pretty well. I'd like to use a
similar approach for other C applications. Can I write a C library that
implements this technique and link it into all C applications that need
Python support, or is there a better, more elegant way?

- in the documentation, there's an example that illustrates the creation
of a python module for pure extending of a python script (the Noddy
stuff). Do I have to make a separate module for each library I want to
wrap? If yes, how can I manage the case where two libraries can access
each other?

- if I write an extension module, how can I handle the case where the C
wrapper methods want to call back into the same Python interpreter instance?

- I think my questions break down into a reference to documentation
where a similar problem is explained in detail. Does anyone have such
information?

Thanks!
Thomas.
Jun 27 '08 #1
1 1328
En Tue, 20 May 2008 06:35:23 -0300, Thomas Troeger
<th****************@siemens.comescribió:
I've successfully embedded the Python interpreter into a set of C/C++
application programs that use a larger library project with information
from http://docs.python.org/api/api.html and
http://docs.python.org/ext/ext.html. Now I want to wrap classes and
functions from the associated libraries so that I can write new
applications completely in Python, but I'm not entirely sure how to
start because I have some problems understanding which is the best way.
It would be nice if someone could answer the following questions and
clarify this matter:

- until now I've used the approach as documented in
http://docs.python.org/ext/extending...embedding.html to extend the
embedded interpreter and that works pretty well. I'd like to use a
similar approach for other C applications. Can I write a C library that
implements this technique and link it into all C applications that need
Python support, or is there a better, more elegant way?
(I don't get what you mean by "this technique" and how would you write a
library)
- in the documentation, there's an example that illustrates the creation
of a python module for pure extending of a python script (the Noddy
stuff). Do I have to make a separate module for each library I want to
wrap? If yes, how can I manage the case where two libraries can access
each other?
Normally, yes, you'd write a wrapping module for each library. If both
access each other - well, you'd manage it the same way as you would do it
in C; you're just providing an interfase for calling the functions from
Python. (Hmm, maybe I have an "imagination crisis" today?)
- if I write an extension module, how can I handle the case where the C
wrapper methods want to call back into the same Python interpreter
instance?
I think there is no problem - unless your program is multithreaded, then
you should not release the GIL when calling into your extension if there
is a chance the C code may call Python code.
--
Gabriel Genellina

Jun 27 '08 #2

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

Similar topics

4
by: Alicia Haumann | last post by:
I accidentally sent this to webmaster@python.org, so this could be a duplicate if "webmaster" forwards it to this list. :{ Hi, there. Thanks for any help that can be offered. I've been...
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...
2
by: Roose | last post by:
With some googling I have found these resources: http://docs.python.org/ext/win-dlls.html http://www.python.org/doc/faq/windows.html I have a large Win32/MFC/C/C++ application that has an...
1
by: Craig Ringer | last post by:
Hi folks I'm a bit of a newbie here, though I've tried to appropriately research this issue before posting. I've found a lot of questions, a few answers that don't really answer quite what I'm...
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: 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...
4
by: adsheehan | last post by:
Hi, I am embedding Python into a multi-threaded C++ application running on Solaris and need urgent clarification on the embedding architecture and its correct usage (as I am experience weird...
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...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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...

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.