2013-05-01 | Paul Boddie | file changeset files shortlog | Added some tests of dynamic attribute access using getattr and string constants. | syspython-as-target |
paul@489 | 1 | #!/usr/bin/env python |
paul@489 | 2 | |
paul@489 | 3 | class A: |
paul@489 | 4 | def f(self, x): |
paul@489 | 5 | return 0 |
paul@489 | 6 | def g(self, y): |
paul@489 | 7 | return 2 |
paul@489 | 8 | |
paul@489 | 9 | class B: |
paul@489 | 10 | def g(self, z): |
paul@489 | 11 | return 4 |
paul@489 | 12 | |
paul@489 | 13 | def f(x, y): # x : A, B |
paul@489 | 14 | result = x.g(1) |
paul@489 | 15 | while y: # x : A only |
paul@489 | 16 | y = x.f(1) |
paul@489 | 17 | return result |
paul@489 | 18 | |
paul@489 | 19 | a = A() |
paul@489 | 20 | b = B() |
paul@489 | 21 | result_2 = f(a, 1) |
paul@489 | 22 | |
paul@489 | 23 | # vim: tabstop=4 expandtab shiftwidth=4 |