[Tutor] Prevent "Coder's Remorse"?

Poor Yorick tutor.python.org at pooryorick.com
Wed Sep 28 22:36:11 CEST 2005


Danny Yoo wrote:

>You may want to change the data structure.
>
>Rather than have points all be peers, reorganize them so that there's some
>kind of hierarchy: that'll help you directly represent the "sharing" of
>attributes.  Explicitly:
>
>#########################################################
>class Point:
>    def __init__(self, lat, lon, atts, parent=None):
>        (self.lat, self.lon, self.atts, self.parent) = (
>              lat, long, atts, parent)
>    def lookup(self, name):
>        if name in self.atts:
>            return self.atts[name]
>        if self.parent:
>            return self.parent.lookup(name)
>        raise KeyError
>#########################################################
>
>  
>

Many thanks Danny.  This example was an moment of epiphany for me, one
that will probably drastically influence me in the future.  I owe you
big time!

--
Poor Yorick



More information about the Tutor mailing list