Calling C function from python

This is the place for queries that don't fit in any of the other categories.

Calling C function from python

Postby ananth » Fri Jun 07, 2013 5:53 am

Hi all,

please can anybody help me in compiling the extension module written in C. (preferably in windows 7 environment)
Mention the steps like where to store this compiled code and how to import this in python.


i have C function of prototype: void F_PC_FMFileManagement(void)
I need to call this above function from python. i have written below interface code.
Code: Select all
[/  //file name Conv.c
#include <python.h>

#include "F_PC_FileManagement_exp.h"

// Implementing the method

static PyObject* Conv_F_PC_FMFileManagement(PyObject *self, PyObject *args)
{

    if (!PyArg_ParseTuple(args,""))
       {return NULL;}

    F_PC_FMFileManagement();
    return Py_BuildValue("");
}
//Declaring the methods

static PyMethodDef ConvMethods[] = {
    {"F_PC_FMFileManagement", Conv_F_PC_FMFileManagement, METH_VARARGS, "Description.."},
    {NULL,NULL,0,NULL}
};

//Initializing the Module
PyMODINIT_FUNC initConv(void)
{
    PyObject *m;
    m = Py_InitModule("Conv",ConvMethods);
    if (m == NULL)
       return;
}
]


Thank you in advance.
Ananth
ananth
 
Posts: 2
Joined: Fri Jun 07, 2013 5:30 am

Re: Calling C function from python

Postby metulburr » Fri Jun 07, 2013 6:33 am

please can anybody help me in compiling the extension module written in C. (preferably in windows 7 environment)
Mention the steps like where to store this compiled code and how to import this in python.

have you read though Creating C extensions
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1507
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: Calling C function from python

Postby setrofim » Fri Jun 07, 2013 8:13 am

See ctypes.
setrofim
 
Posts: 288
Joined: Mon Mar 04, 2013 7:52 pm

Re: Calling C function from python

Postby ananth » Fri Jun 07, 2013 10:13 am

Thank you metulburr and setrofim.
ananth
 
Posts: 2
Joined: Fri Jun 07, 2013 5:30 am


Return to General Coding Help

Who is online

Users browsing this forum: Baidu [Spider] and 4 guests