From: Gerald B. <ger...@gm...> - 2009-02-02 12:05:43
|
Its in the properties stmt. Order is get, set, del, descriptor, IIRC. On 2/2/09, Gary Burton <bur...@ya...> wrote: > Hello Don, > > Thanks for posting these little tutorials on modern Python - keep them > coming as I find them very useful. My OO language knowledge is rooted in > Java, so my current Python knowledge is based on what I have been able to > bring across from Java and learning from the existing Gramps codebase, which > as you say uses a dated Python style. > > > Question about the setter/getter example. > >> class Person: >> >> def __init__(self): >> self.__age = 0 >> >> def __get_age(self): >> return self.__age >> >> def __set_age(self, x): >> self.__age = x if x >= 0 else 0 >> >> age = property(__get_age, __set_age) >> >> Now, assigning to "age" will call self.__set_age(), and reading "age" >> will call self.__get_age() > > How does Python distinguish between the setter and getter methods? Is there > an implicit naming convention that Python assumes e.g. __get_age() must be a > get method because it is prefixed __get? Or is it the ordering of the > methods in the property assignment that does it? > > Bye > > Gary > > > > > > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by: > SourcForge Community > SourceForge wants to tell your story. > http://p.sf.net/sfu/sf-spreadtheword > _______________________________________________ > Gramps-devel mailing list > Gra...@li... > https://lists.sourceforge.net/lists/listinfo/gramps-devel > -- Sent from my mobile device |