Subattributes of classes

Charles G Waldman cgw at fnal.gov
Mon Apr 5 12:04:18 EDT 1999


Randall Hopper wrote:

 > Why?

Because "attr" in class A is just an int, and has no attributes,
whereas "draw" in the Tkinter demo is a Canvas object, which has a
scrollX and scrollY attribute.

Consider this example:

class B:
    def __init__(self):
        self.subattr = None

class A:
    def __init__(self):
        self.attr = B()
        self.attr.subattr = 456

a = A()

print a.attr.subattr




More information about the Python-list mailing list