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@641 | 1 | #!/usr/bin/env python |
paul@641 | 2 | |
paul@641 | 3 | class A: |
paul@641 | 4 | pass |
paul@641 | 5 | |
paul@641 | 6 | class B(A): |
paul@641 | 7 | pass |
paul@641 | 8 | |
paul@641 | 9 | class C: |
paul@641 | 10 | pass |
paul@641 | 11 | |
paul@641 | 12 | def f(x): |
paul@641 | 13 | return x.__class__ |
paul@641 | 14 | |
paul@641 | 15 | a = f(A) |
paul@641 | 16 | b = f(B) |
paul@641 | 17 | c = f(C) |
paul@641 | 18 | |
paul@641 | 19 | result_1 = a is type and 1 or 0 |
paul@641 | 20 | result_2 = b is type and 2 or 0 |
paul@641 | 21 | result_3 = c is type and 3 or 0 |
paul@641 | 22 | |
paul@641 | 23 | # vim: tabstop=4 expandtab shiftwidth=4 |