Passing FILE * types using ctypes

Gregory Ewing greg.ewing at
Fri Mar 5 09:10:01 CET 2010

Francesco Bochicchio wrote:

> Python file objects have a method fileno() whic returns the 'C file
> descriptor', i.e. the number used by low level IO in python as well as
> in C.
> I would use this as interface between python and C and then in the C
> function using fdopen to get a FILE * for an already open file for
> which you have a file descriptor.

But note that this will be a *new* stdio file buffer
attached to the same file descriptor, not the same one
that the Python file object is using. This may or may
not be a problem depending on what you're trying to

If you need the same FILE * that Python is using, you
may need to use ctypes to extract it out of the file


More information about the Python-list mailing list