Re: C Module question

2008-11-14 Thread Gabriel Genellina
En Mon, 10 Nov 2008 11:44:44 -0200, [EMAIL PROTECTED] <[EMAIL PROTECTED]> escribió: On Nov 10, 2:23 pm, Floris Bruynooghe <[EMAIL PROTECTED]> 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*

Re: C Module question

2008-11-10 Thread greg
[EMAIL PROTECTED] wrote: Sadly this doesn't work on "file-like" objects like those that are created by opening bz2 files (using the bz2 lib). If the C code you're calling requires a FILE *, then you're out of luck. There's no way of getting a FILE * from an object that's not based on an actual

Re: C Module question

2008-11-10 Thread John Machin
On Nov 11, 12:55 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > On Mon, 10 Nov 2008 05:44:44 -0800, [EMAIL PROTECTED] wrote: > > All in all I must say that implementing a C extension is a piece of > > cake. Had I known that it was this straightforward I wouldn't have asked > > my questio

Re: C Module question

2008-11-10 Thread Marc 'BlackJack' Rintsch
On Mon, 10 Nov 2008 05:44:44 -0800, [EMAIL PROTECTED] wrote: > All in all I must say that implementing a C extension is a piece of > cake. Had I known that it was this straightforward I wouldn't have asked > my questions in the first place. Making the whole thing more robust will > be a bit more d

Re: C Module question

2008-11-10 Thread Marc 'BlackJack' Rintsch
On Mon, 10 Nov 2008 05:36:58 -0800, [EMAIL PROTECTED] wrote: > On Nov 10, 1:16 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: >> On Mon, 10 Nov 2008 03:11:06 -0800, [EMAIL PROTECTED] wrote: >> > 1. How can I pass a file-like object into the C part? The PyArg_* >> > functions can convert o

Re: C Module question

2008-11-10 Thread [EMAIL PROTECTED]
On Nov 10, 2:23 pm, Floris Bruynooghe <[EMAIL PROTECTED]> 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" obje

Re: C Module question

2008-11-10 Thread [EMAIL PROTECTED]
On Nov 10, 1:16 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > On Mon, 10 Nov 2008 03:11:06 -0800, [EMAIL PROTECTED] wrote: > > 1. How can I pass a file-like object into the C part? The PyArg_* > > functions can convert objects to all sort of types, but not FILE*. > > http://docs.python.

Re: C Module question

2008-11-10 Thread Floris Bruynooghe
On Nov 10, 1:18 pm, Floris Bruynooghe <[EMAIL PROTECTED]> wrote: > On Nov 10, 11:11 am, "[EMAIL PROTECTED]" > > <[EMAIL PROTECTED]> wrote: > > 1. How can I pass a file-like object into the C part? The PyArg_* > > functions can convert objects to all sort of types, but not FILE*. > > Parse it as a g

Re: C Module question

2008-11-10 Thread Floris Bruynooghe
Hi On Nov 10, 11:11 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > 1. How can I pass a file-like object into the C part? The PyArg_* > functions can convert objects to all sort of types, but not FILE*. Parse it as a generic PyObject object (format string of "O" in PyArg_*), check the type a

Re: C Module question

2008-11-10 Thread Marc 'BlackJack' Rintsch
On Mon, 10 Nov 2008 03:11:06 -0800, [EMAIL PROTECTED] wrote: > 1. How can I pass a file-like object into the C part? The PyArg_* > functions can convert objects to all sort of types, but not FILE*. http://docs.python.org/c-api/file.html#PyFile_AsFile > 2. How can I preserve information needed in

Re: C Module question

2008-11-10 Thread Christian Heimes
[EMAIL PROTECTED] wrote: Hello, I'm trying to write a Python extension module in C for the first time. I have two questions: I have a much better suggestion: Use Cython! Although I'm pretty experienced with the Python C API, I prefer Cython over hand written C code for most stuff. It's s