C Module question

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Fri Nov 14 22:26:28 EST 2008


En Mon, 10 Nov 2008 11:44:44 -0200, boblatest at googlemail.com  
<boblatest at googlemail.com> escribió:

> On Nov 10, 2:23 pm, Floris Bruynooghe <floris.bruynoo... at gmail.com>
> wrote:
>
>> Sorry, I probably should have mentioned you want to cast the object to
>> PyFileObject and then use the PyFile_AsFile() function to get the
>> FILE* handle.
>
> Yes, I figured that out by now. Sadly this doesn't work on "file-like"
> objects like those that are created by opening bz2 files (using the
> bz2 lib). Not that I have any idea on how that should work anyway.

Call the file-like methods as you would with any other object method. That  
is, if you got an object `fobj` from Python and you want to write a C  
string:

	char* str="some text\n";
	PyObject_CallMethod(fobj, "write", "s", str)

See also PyObject_CallObject and the other variants:  
http://docs.python.org/c-api/object.html#PyObject_Call

-- 
Gabriel Genellina




More information about the Python-list mailing list