About getattr()

Leif K-Brooks eurleif at ecritters.biz
Sun Feb 11 23:59:44 EST 2007


Jm lists wrote:
> Since I can write the statement like:
> 
>>>> print os.path.isdir.__doc__
> Test whether a path is a directory
> 
> 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. getattr() is only useful when the attribute name is 
determined at runtime.



More information about the Python-list mailing list