2017-01-21 | Paul Boddie | file changeset files shortlog | Made class and function instance __name__ attributes leafnames, introducing a separate __mname__ attribute on classes and function instances to help support the reproduction of the full path of those objects. Updated the visitor example to use the __name__ attributes of node classes instead of special name attributes. |
paul@326 | 1 | import operator |
paul@326 | 2 | |
paul@326 | 3 | class C: |
paul@326 | 4 | pass |
paul@326 | 5 | |
paul@326 | 6 | c = C() |
paul@489 | 7 | print c.__name__ # C |
paul@489 | 8 | print c.__mname__ # __main__ |
paul@489 | 9 | print C.__name__ # C |
paul@489 | 10 | print C.__mname__ # __main__ |
paul@326 | 11 | |
paul@489 | 12 | # If it were defined, operator.__name__ would be module. |
paul@326 | 13 | |
paul@489 | 14 | print operator.__mname__ # operator |
paul@326 | 15 | |
paul@489 | 16 | # If it were defined, operator.add.__name__ would be function. |
paul@326 | 17 | |
paul@489 | 18 | print operator.add.__fname__ # add |
paul@489 | 19 | print operator.add.__mname__ # operator.binary |