[Tutor] Class attributes not overriding parameters

Liam Clarke ml.cyresse at gmail.com
Sun Nov 6 05:45:17 CET 2005


Hi Jan,

Won't this

site_id = property(GetSiteID, SetSiteID)

and this

site_id = 1

collide?

On 11/6/05, Jan Eden <lists at janeden.org> wrote:
> Hi,
>
> I use the following construction to make sure the data attribute site_id is set only once for each object:
>
> def GetSiteID(self):
>     return self._site_id
>
> def SetSiteID(self, value):
>     if not (hasattr(self, '_site_id') and self._site_id): self._site_id = value
>
> site_id = property(GetSiteID, SetSiteID)
>
> site_id is supposed to be set either through a parameter, derived from the server name (the default case) or via a class attribute:
>
> class SiteList(Lists):
>     site_id = 1
>
> The latter case does not work: the site_id is still derived from the server name for objects of class SiteList. Why is that? How can I make Python check the superclasses for a class attribute before applying the SiteMode() method?
>
> Thanks,
>
> Jan
> --
> How many Microsoft engineers does it take to screw in a lightbulb? None. They just redefine "dark" as the new standard.
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>


More information about the Tutor mailing list