C# creates collections in using IEnumerator,IEnumerable interfaces. The same approch can be followed in Ironpython by importing System.Collections namespace. Here i am following classic CPython approch. So i am not using any .NET Name spaces
C# creates collections in using IEnumerator,IEnumerable interfaces. The same approch can be followed in Ironpython by #importing System.Collections namespace. Here i am following classic CPython approch. So i am not using any .NET Name #spaces
Generating Fibnocci series
class fibnum:
def __init__(self):
self.fn2 = 1 #
self.fn1 = 1 #
def next(self):
# next() is the heart of any iterator
# note the use of the following tuple to not only save lines of
# code but also to insure that only the old values of self.fn1 and
# self.fn2 are used in assigning the new values
(self.fn1,self.fn2,oldfn2) = (self.fn1+self.fn2,self.fn1,self.fn2)
return oldfn2
def __iter__(self):
return self
def main():
f = fibnum()
for i in f:
print i
if i > 20: break
if __name__ == "__main__":
main()