Python Forum
API-C: call the next value from a generator - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: API-C: call the next value from a generator (/thread-4860.html)



API-C: call the next value from a generator - mcanonic - Sep-11-2017

Hi all,
this is my first post and I hope that I select the right thread.
The following python code is working and I can call it from my C source code (I followed the example provided here: https://docs.python.org/2/extending/embedding.html):
def main:
    rndWP = RndWP(300, 100, 100, 10, 100, 0)
    x =rndWP.NextPlese()
    return x
RndWP is a class which create a generator: the constructor set all parameters (300, 100, ...) while "NextPlease" is the function of the class which extracts the new value.

Now the problem is that I would like to call NextPlease function from my C code and get the new number from the generator. Right now my C code is able to run the "main" function and get the first number. Ho can I get the second number, the third number and so on?

I'm using python 2.7 due to compatibility problem with the generator (that is, I cannot switch to python3).

Any suggestion is more than welcome.

Thanks,
M