micropython

tests/attributes_instance_assignment.py

519:814bd122d84d
2012-06-04 Paul Boddie Updated the documentation to reflect class attribute assignment policies. Added tests to demonstrate class attribute rebinding.
     1 #!/usr/bin/env python     2      3 class C:     4     def __init__(self, x):     5         self.x = x     6         self.z = None     7      8 class D:     9     def __init__(self, y):    10         self.y = y    11         self.z = None    12     13 def f(a):    14     if a.z:    15         pass    16     a.x = 3    17     18 def g(a):   # {{z}, {x, z}}    19     if a.z:    20         a.x # {x, z}    21             # {z} (else)    22     a.z = 4    23     24 c = C(1)    25 d = D(0)    26 f(c)    27 g(d)    28 result_3 = c.x    29 result_4 = d.z    30     31 # vim: tabstop=4 expandtab shiftwidth=4