Lichen

tests/getattr.py

934:2989aab1b4f7
7 months ago Paul Boddie Renamed the utf8string class to unicode, eliminating the unicode function. This means that the simple case of merely returning an object if it is already a Unicode object no longer occurs when using the unicode callable, but such behaviour might be better supported with more general customised instantiation functionality.
     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