passing FILE pointers to a non-MSVC++ compiled extension type???

doug doug_bartholomew99 at yahoo.com
Sat Aug 11 15:58:54 EDT 2001


"Alex Martelli" <aleaxit at yahoo.com> wrote in message news:<9l0cgv0229h at enews4.newsguy.com>...
> Yes, PyFile_WriteString should serve your purposes (you'll pass
> your C-like string as a char* first argument, a PyObject* for the
> relevant Python file-like object as the second argument -- there's
> a bug in the docs, they mention an unexplained third 'flags'
> argument, but fileobject.h and fileobject.c show there is nothing
> of the kind -- I've just submitted a correction to sourceforge).
> 
> 
> Alex

Ok, I have two quick follow up questions:

1) what is the correct way to construct the Python file-like object? 
Having looked at the documentation and the source, i put together:

   PyObject* py_file = PyFile_FromFile(fp, "somename", "DUNNO", NULL);
   PyFile_WriteString(char_pointer, py_file);
   Py_XDECREF(py_file);

which does in fact work fine.  but what do the name, mode and close
arguments of PyFile_FromFile() actually do?  i dont want to accidently
create a bug that ill never be able to track down in 6 months.

2) the first argument to PyFile_WriteString() is a char*.  shouldnt
this be a const char* type?  surely PyFile_WriteString() doesnt need
to make any changes to the string.  i tried to be const correct and
pass in a const char* but it generated a compiler error.



More information about the Python-list mailing list