By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,941 Members | 1,766 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,941 IT Pros & Developers. It's quick & easy.

Generators in C code

P: n/a
Hi

I'd like to write a generator in C, callable from Python.
The only way to create a generator object I can see, is using
PyGen_New(frame) - and a frame object implies Python code, right? holding
global state and local variables and stack and a lot of stuff, so perhaps
there is no (easy) way I could write that in C code.
Or perhaps some way to execute a yield statement inside a C function?
Being able to resume execution at the same point later?
I feel I'm out of luck, but if someone could point some way to write a
generator in C, I'be very grateful!

--
Gabriel Genellina

May 15 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On May 14, 9:55 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
wrote:
I feel I'm out of luck, but if someone could point some way to write a
generator in C, I'be very grateful!
Perhaps the code in the itertools module will provide a good example
-- they behave like generators in many respects except that you are
responsible for tracking state and jumping to an appropriate resume
point. Being C, it won't be as convenient as Python generators, but
should be able to translate any generator into equivalent C.
Raymond Hettinger
May 15 '07 #2

P: n/a
En Tue, 15 May 2007 02:12:40 -0300, Raymond Hettinger <py****@rcn.com>
escribió:
>I feel I'm out of luck, but if someone could point some way to write a
generator in C, I'be very grateful!

Perhaps the code in the itertools module will provide a good example
-- they behave like generators in many respects except that you are
responsible for tracking state and jumping to an appropriate resume
point. Being C, it won't be as convenient as Python generators, but
should be able to translate any generator into equivalent C.
Oh, thanks for pointing that! (I didn't know the itertools module was
written in C - I supposed it was a Python module).
After a brief reading, I think I'll use something similar to how tee and
teedataobject store current state.

--
Gabriel Genellina

May 15 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.