Getting the docstring of a property

John Roth newsgroups at
Wed Aug 11 14:31:53 CEST 2004

"Andrew Durdin" <adurdin at> wrote in message
news:mailman.1493.1092226382.5135.python-list at
> How do you get the docstring of a property? Suppose I have the following:
> class Foo:
>     def _prop_get(self):
>         return 1
>     prop = property(_prop_get, doc="This is the docstring")
> foo = Foo()
> print foo.prop
> print foo.prop.__doc__
> This will display "1", followed by the docstring for an integer (which
> is the docstring for the int() function). How can I get the property's
> docstring as defined in the property() function?

You tried to access it from the instance. However, accessing it from the
instance invoked the property, returning 1, before it attempted to
access the docstring.

You need to get it from the class. That is:


should do what you want.

John Roth

More information about the Python-list mailing list