getattr on objects
Ian Bicking
ianb at colorstudy.com
Tue Oct 8 16:40:42 EDT 2002
More information about the Python-list mailing list
Tue Oct 8 16:40:42 EDT 2002
- Previous message (by thread): SOT : & in XML-documents
- Next message (by thread): getattr on objects
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Tue, 2002-10-08 at 05:41, bromden wrote: > I wanted to make a class which would pretend to have any > method you can call on it (returning some default value). > Defined a class: > >>> class C: > ... def hasattr(self, name): return 1 > ... def getattr(self, name): return self.default > ... def default(self): return 'default' [snip] More generally, there's a bunch of "magic" methods in Python to do this sort of thing, described here: http://www.python.org/doc/current/ref/specialnames.html Ian
- Previous message (by thread): SOT : & in XML-documents
- Next message (by thread): getattr on objects
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list