User Access to the docstring of a property

georgeryoung at gmail.com georgeryoung at gmail.com
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.
If
the application is run with optimization turned on, docstrings are
usually
optimized out.  Docstrings are handy for reading code and maybe for
debugging, but should not be relied upon for "users", as opposed to
developers.

-- 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