user422005 user422005 - 1 year ago 119
Python Question

Python ctypes: Python file object <-> C FILE *

I am using ctypes to wrap a C-library (which I have control over) with Python. I want to wrap a C-function with declaration:

int fread_int( FILE * stream );

Now; I would like to open file in python, and then use the Python file-object (in some way??) to get access to the underlying FILE * object and pass that to the C-function:

# Python
fileH = open( file , "r")
value = ctypes_function_fread_int( ????? )

Is the Python file <-> FILE * mapping at all possible?


Answer Source

I've encountered the same problem.

Take a look at this file:

You can use PyFile_AsFile from it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download