Getters and Setters
Neil Schemenauer
nascheme at ucalgary.ca
Thu Jul 15 18:25:25 EDT 1999
More information about the Python-list mailing list
Thu Jul 15 18:25:25 EDT 1999
- Previous message (by thread): Getters and Setters
- Next message (by thread): Getters and Setters
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Bernhard Herzog <herzog at online.de> wrote: >So, putting the functions into the class would be better: > > def getter(self, key=name[3:]): > return getattr(self, key) > setattr(self.__class__, name, getter) > return getattr(self, name) This is a very nice solution. Thanks Bernhard. It is a little slower than Tim's method but avoids creating circular references and doesn't create a function for each instance. It also works for class variables. Neil
- Previous message (by thread): Getters and Setters
- Next message (by thread): Getters and Setters
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list