User Access to the docstring of a property

Colin J. Williams cjw at sympatico.ca
Sat Oct 21 12:38:12 EDT 2006


George,

Thanks to Dietz and yourself.

Yes, I should have referenced the class, rather than the instance. 
However, for methods, the docstring is revealed for an instance.

Colin W.

PS It would help if someone could explain the use of @apply in the 
example Dietz gave.  The documentation gives no reference to @ or to 
decorators.

georgeryoung at gmail.com wrote:
> 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