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

Calling python functions from C

I am a newbie to Python. I want to call python functions from C. I
looked for examples but I couldn't get any simple one. Lets say my
python code is :
def add(a,b)
return (a+b)

I want to call add from C. Could anybody please help me? Thanks in
advance.

R.

May 10 '06 #1
5 2056
ro*****************@gmail.com wrote:
I want to call add from C. Could anybody please help me?


Look at the "Pure Embedding" section of the python documentation. It
contains an example program that does exactly what you want. Here is a
link to the page:

http://www.python.org/doc/ext/pure-embedding.html

-Farshid
May 10 '06 #2
On 9 May 2006 10:05:48 -0700, ro*****************@gmail.com wrote:
I am a newbie to Python. I want to call python functions from C. I
looked for examples but I couldn't get any simple one. Lets say my
python code is :
def add(a,b)
return (a+b)

I want to call add from C. Could anybody please help me? Thanks in
advance. This is also known as "callback".

Check out
http://www.google.com/search?client=...utf-8&oe=utf-8
or
http://www.python.org/doc/current/ext/ext.html

-RM
R.

May 10 '06 #3
Thanks Farshid,

Thats helps me alot !

R.
Farshid Lashkari wrote:
ro*****************@gmail.com wrote:
I want to call add from C. Could anybody please help me?


Look at the "Pure Embedding" section of the python documentation. It
contains an example program that does exactly what you want. Here is a
link to the page:

http://www.python.org/doc/ext/pure-embedding.html

-Farshid


May 10 '06 #4
Thanks Ronny,

R.

Ronny Mandal wrote:
On 9 May 2006 10:05:48 -0700, ro*****************@gmail.com wrote:
I am a newbie to Python. I want to call python functions from C. I
looked for examples but I couldn't get any simple one. Lets say my
python code is :
def add(a,b)
return (a+b)

I want to call add from C. Could anybody please help me? Thanks in
advance.

This is also known as "callback".

Check out
http://www.google.com/search?client=...utf-8&oe=utf-8
or
http://www.python.org/doc/current/ext/ext.html

-RM

R.


May 10 '06 #5
ro*****************@gmail.com wrote:
I am a newbie to Python. I want to call python functions from C. I
looked for examples but I couldn't get any simple one. Lets say my
python code is :
def add(a,b)
return (a+b)

I want to call add from C. Could anybody please help me? Thanks in
advance.

R.


You might look at elmer <http://elmer.sourceforge.net/>

Quote:
What is elmer?
Elmer is a tool which embeds a Python module into a C, C++, or Tcl
application. The embedded Python module is used just as if it was
written in the same language as the application itself, without
requiring any knowledge of the Python/C API.

Elmer generates "glue" code that embeds an interpreter for one type of
language into an extension for another. Elmer allows function calls and
various data types, both native and custom, to pass transparently
between the two languages.
--
Nigel Rowe
A pox upon the spammers that make me write my address like..
rho (snail) swiftdsl (stop) com (stop) au
May 12 '06 #6

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

Similar topics

10
by: Kyler Laird | last post by:
I need to submit C/C++ code for a class. (It's not a programming class. The choice of language is inertial. I think that it mostly serves to distract students from the course subject.) I'm...
0
by: Natsu Mizutani | last post by:
Hello, I'm trying to wrap a c++ library using MPI inside with boost.python (or SWIG). I managed to find that calling `MPI::Init()` embeded in a c++ funtion would not work. So, I decided to use...
18
by: bart_nessux | last post by:
I need a script to call several functions at the same time. How does one call more than one function simultaneously?
1
by: delrocco | last post by:
Hello, I really appreciate anyone who has time to read this and help, Thanks up front. I'm very new to python, having picked it up for the first time a week ago, but I feel I'm very close to...
6
by: Yevgeniy (Eugene) Medynskiy | last post by:
Hi all, This is probably a very newbie question, but after searching google and docs @ python.org I can't find an answer, so maybe someone would be able to help? I'd like to call command-line...
1
by: Gerald Klix | last post by:
I read the whol email thread carefully and could not find any sentence by Guido, which states that he does not accept ctypes for the standard library. He just declined to rewrite winreg. Did I miss...
3
by: David Bear | last post by:
I have a hash function written by another organization that I need to use. It is implemented in perl. I've been attempting to decode what they are doing in their hash function and it is taking way...
4
by: Edwin Gomez | last post by:
I'm a C# developer and I'm new to Python. I would like to know if the concept of Asynchronous call-backs exists in Python. Basically what I mean is that I dispatch a thread and when the thread...
47
by: teju | last post by:
hi, i am trying 2 merge 2 projects into one project.One project is using c language and the other one is using c++ code. both are working very fine independently.But now i need to merge both...
16
by: Jaco Naude | last post by:
Hi there, This is my first post over here and I hope someone can give me some guidance. I'm trying to embed Python into a Visual C++ 2008 application and I'm getting linker problems. I've...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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.