FILE object in Python3.0 extension modules

Joachim Dahl dahl.joachim at
Fri May 29 05:52:15 EDT 2009

In Python2.x, I used PyFile_Check(obj) to check if a parameter was a
file object.

Now, in Python3.0 the same object (obtained as open('file.bin','wb'))
is an
io.BufferedWriter object.

How do I perform type checking for such an object in the extension
and how do I extract a FILE * object from it?  I browsed the C API
documentation,  but
couldn't find an answer.

The purpose is to dump the contents of a Python extension type to disk
binary data using C's fwrite() function.

More information about the Python-list mailing list