2013-06-30 | Paul Boddie | file changeset files shortlog | Permit analysis of the getattr function itself, thus exposing _getattr. | syspython-as-target |
paul@655 | 1 | #!/usr/bin/env python |
paul@655 | 2 | |
paul@655 | 3 | class C: |
paul@655 | 4 | def x(self): |
paul@655 | 5 | return 1 |
paul@655 | 6 | |
paul@655 | 7 | class D: |
paul@655 | 8 | def x(self): |
paul@655 | 9 | return 2 |
paul@655 | 10 | |
paul@655 | 11 | def f(obj, attrname): |
paul@655 | 12 | return getattr(obj, attrname) |
paul@655 | 13 | |
paul@655 | 14 | c = C() |
paul@655 | 15 | d = D() |
paul@655 | 16 | result_1 = f(c, "x")() |
paul@655 | 17 | result_2 = f(d, "x")() |
paul@655 | 18 | |
paul@655 | 19 | # vim: tabstop=4 expandtab shiftwidth=4 |