2017-02-18 | Paul Boddie | file changeset files shortlog | Introduced a context test that sets a local context for static attributes. | method-wrapper-for-context |
paul@507 | 1 | class fib: |
paul@507 | 2 | def __init__(self): |
paul@507 | 3 | self.a, self.b = 0, 1 |
paul@507 | 4 | |
paul@507 | 5 | def next(self): |
paul@507 | 6 | result = self.b |
paul@508 | 7 | self.a, self.b = self.b, self.a + self.b |
paul@507 | 8 | return result |
paul@507 | 9 | |
paul@507 | 10 | seq = fib() |
paul@507 | 11 | i = 0 |
paul@507 | 12 | while i < 10: |
paul@507 | 13 | print seq.next() |
paul@507 | 14 | i += 1 |