2013-10-31 | Paul Boddie | file changeset files shortlog | Added remarks about local namespaces and name usage observations. | syspython-as-target |
paul@655 | 1 | #!/usr/bin/env python |
paul@655 | 2 | |
paul@655 | 3 | class C: |
paul@655 | 4 | def x(self, obj): |
paul@655 | 5 | return getattr(obj, "y")(obj) |
paul@655 | 6 | |
paul@655 | 7 | def y(self, obj): |
paul@655 | 8 | return getattr(obj, "z")(obj) |
paul@655 | 9 | |
paul@655 | 10 | def z(self, obj): |
paul@655 | 11 | return 1 |
paul@655 | 12 | |
paul@655 | 13 | class D: |
paul@655 | 14 | def x(self): |
paul@655 | 15 | return 2 |
paul@655 | 16 | |
paul@655 | 17 | def f(obj, attrname): |
paul@655 | 18 | return getattr(obj, attrname)(obj) |
paul@655 | 19 | |
paul@655 | 20 | c = C() |
paul@655 | 21 | d = D() |
paul@655 | 22 | result_1 = f(c, "x")() |
paul@655 | 23 | result_2 = f(d, "x")() |
paul@655 | 24 | |
paul@655 | 25 | # vim: tabstop=4 expandtab shiftwidth=4 |