User Access to the docstring of a property

georgeryoung at georgeryoung at
Fri Oct 20 17:32:30 CEST 2006

Colin J. Williams wrote:
> Is there some way that the user can access the docstring specified for a
> property?

Do keep in mind that the docstring is not guaranteed to be available.
the application is run with optimization turned on, docstrings are
optimized out.  Docstrings are handy for reading code and maybe for
debugging, but should not be relied upon for "users", as opposed to

-- George Young

> Please see the example below:
> # propDocTest
> class A(object):
>    def __init__(self, value):
>      self.value= value
>    def vGet(self):
>      return self.value
>    V= property (fget= vGet, doc="Get Value.")
> a= A(22)
> print a.vGet()
> print a.V
> print a.V.__doc__     # this gives the docstring for the value returned
> help(a.V)             # this gives the docstring for the class/type of
> the value returned
> Colin W.

More information about the Python-list mailing list