> You can also replace the whole class with a function thusly:
>
>    def two_times(n):
>        for k in itertools.count(1):
>            yield n * (2**k)
>
> This function is then called a generator (because it generates an
> iterator). You can now say
>
>    infinitely_doubling_numbers = two_times(2)
>    for number in in infinitely_doubling_numbers:
>        print number

Oh..this is new. Will checkup itertools. Thanks.

>> t = twoTimes(5)
>> while (n in t.getNext()): # while (n in t):
>>     print (n)
>>
> You are aware that this is an infinite loop, as is my example above BTW?
> (Probably just an example, but I ask just in case.)

I was aware this was an infinite loop - just didnt want to put more
code for an example.
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to