__doc__ string for getset members

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sun Apr 7 17:35:50 EDT 2013


On Sun, 07 Apr 2013 21:21:03 +0100, Arnaud Delobelle wrote:

> On 7 April 2013 19:02, Nick Gnedin <ngnedin at gmail.com> wrote:
[...]
>> My question is - how do I access the doc string "mem-doc-string"
>> supplied in the PyGetSetDef structure? If I type
>>
>> print(obj.mem.__doc__)
>>
>> then the __doc__ string for the result of a call to MemGet(...) is
>> printed, not the doc string supplied in the PyGetSetDef structure.
>>
>>
> That's not how Python works.  You won't be able to get the docstring of
> a descriptor this way.  You need to do it from the class.  The behaviour
> you observe is normal and cannot be overriden.


All very well and good, but how about putting Nick out of his misery and 
showing how to do it?


print(obj.__class__.mem.__doc__)


ought to work.



-- 
Steven



More information about the Python-list mailing list