Nested Classes and Instances

Manuel Graune manuel.graune at koeln.de
Fri Jul 10 13:00:11 EDT 2009


Hello,

as an example of what I would like to achieve, think of a street
where each house has a door and a sign with a unique (per house)
number on it. I tried to model this like this:

class House(object):
    class Door(object):
        def __init__(self,color):
             self.color=color
    class Sign(object):
        def __init__(self,text):
             self.text=text
    def __init__(self, doorcolor,housenumber):
        self.housenumber=housenumber
        self.door=House.Door(doorcolor)
        self.sign=House.Sign(housenumber)

house1=House("red","1")
house2=House("blue","2")

Well, so far, so good. Now, what I'd like to achive is that the text of
the "sign" changes whenever the variable "housenumber" of the
"parent-instance" changes or  that
"house1.sign.text" is a reference/pointer to "house1.housenumber"

Thanks in advance,

Manuel



-- 
A hundred men did the rational thing. The sum of those rational choices was
called panic. Neal Stephenson -- System of the world
http://www.graune.org/GnuPG_pubkey.asc
Key fingerprint = 1E44 9CBD DEE4 9E07 5E0A  5828 5476 7E92 2DB4 3C99



More information about the Python-list mailing list