Lichen

tests/getattr.py

813:a80de062b595
2017-04-11 Paul Boddie Expanded the download documentation and added a changelog page.
     1 class C:     2     def __init__(self):     3         self.x = 1     4         self.y = 2     5         self.z = 3     6      7 class D:     8     def __init__(self):     9         self.x = 4    10         self.y = 5    11         self.z = 6    12     13 c = C()    14 d = D()    15     16 attrnames = ["a", "b", "c", "x", "y", "z"]    17     18 print ". c d"    19     20 for attrname in attrnames:    21     print attrname, hasattr(c, attrname) and "1" or "0", hasattr(d, attrname) and "1" or "0"    22     23 print    24 print ". c d"    25     26 for attrname in attrnames:    27     print attrname,    28     try:    29         v = getattr(c, attrname)    30         print v,    31     except AttributeError:    32         print "?",    33     34     try:    35         v = getattr(d, attrname)    36         print v    37     except AttributeError:    38         print "?"    39     40 try:    41     setattr(c, "x", 7)    42 except NotImplementedError, exc:    43     print 'setattr(c, "x", 7): not implemented:', exc.name