How to receive a FILE* from Python under MinGW?
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Wed Mar 21 02:08:23 EDT 2007
En Wed, 21 Mar 2007 01:58:05 -0300, John Pye <john.pye at gmail.com> escribió:
> Hmm. Reading this again I think I understand properly now. The
> 'fileno' is really *not* the same thing as the FILE* pointer cast to
> an integer. It is a lower-level structure.
Just an integer. But as Ross Ridge has pointed out, it's not an OS thing
on Windows, it's faked by the C runtime.
> The question is now, if I don't want to modify my *python* code, how
> do I get at the 'fileno' property of my PyFileObject?
From Python, calling the fileno() method. From C, using
fileno(PyFile_AsFile(your_file_object))
And then, using get_osfhandle(fd)
> Also, are there consequences for using this approach of regenerating
> the FILE struct? For example if I have the following:
>
> F = os.tmpfile()
> F.write("some data")
> F.seek(0)
> myswigmodule.dosomething(F)
> F.seek(0)
> S = F.read()
> print S
Just try it and let us know what happens! :)
> I don't know enough about this low-level file handling to really
> understand the implications of what you are proposing -- perhaps you
> could explain a little?
It's too late (for me) now, but if you can't make it work I'll try an
example tomorrow.
--
Gabriel Genellina
More information about the Python-list
mailing list