[Q] Accessors...
Gordon McMillan
gmcm at hypernet.com
Mon Jul 19 12:52:27 EDT 1999
More information about the Python-list mailing list
Mon Jul 19 12:52:27 EDT 1999
- Previous message (by thread): [Q] Accessors...
- Next message (by thread): [Q] Accessors...
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Olivier Deckmyn writes: > > Is there a way to do the following : > > class MyClass : > def __init__(self): > self._myAttr = None > > def get_myAttr(self): > return self._myAttr > > def set_myAttr(self, value) > self._myAttr = value # might do more interresting checkings > for > examples > > > and then use this like that: > > m=MyClass() > m.myAttr="foo" > print m.myAttr You need to get used to Python's dynamism. class A: pass a = A() a.foo = 'bar' If I've misunderstood your question, there was a recent thread "Getters and Setters" about tricky ways to automatically create get and set methods for attributes, so that given an instance of class A with attribute foo, the user could write: a = A() a.getfoo() without the programmer creating the getfoo method. But if that's not what you want, don't go there! - Gordon
- Previous message (by thread): [Q] Accessors...
- Next message (by thread): [Q] Accessors...
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list