Leif K-Brooks <[EMAIL PROTECTED]> wrote: >> Why do I still need the getattr() func as below? >> >>>>> print getattr(os.path,"isdir").__doc__ >> Test whether a path is a directory > > You don't.
Correct > getattr() is only useful when the attribute name is > determined at runtime. > getattr() is useful in at least 2 other situations: maybe you know the attribute name in advance, but don't know whether the object has that particular attribute, then the 3 argument form of getattr could be appropriate: print getattr(x, 'attr', 'some default') or if the attribute name isn't a valid Python identifier: print getattr(x, 'class') -- http://mail.python.org/mailman/listinfo/python-list