property docstrings

Ziga Seilnacht ziga.seilnacht at gmail.com
Fri Mar 24 12:26:22 EST 2006


Darren Dale wrote:
> I am trying to work with properties, using python 2.4.2. I can't get the
> docstrings to work, can someone suggest what I'm doing wrong? I think the
> following script should print "This is the doc string.", but instead it
> prints:
>
> "float(x) -> floating point number
>
> Convert a string or number to a floating point number, if possible."
>
> Thanks,
> Darren

<snip>

> a=Example()
> print 'myattr docstring:\n', a.myattr.__doc__
> print 'foo docstring:\n', a.foo.__doc__
> print 'bar docstring:\n', a.bar.__doc__

change this part to:

print 'myattr docstring:\n', Example.myattr.__doc__
print 'foo docstring:\n', Example.foo.__doc__
print 'bar docstring:\n', Example.bar.__doc__

What happens is that when property is accessed
from an instance, it returns whatever the fget
function returns, and the __doc__ attribute
is then looked up on that object.

To get to the actual property object (and its
__doc__ attribute) you have to access it from
a class.

Ziga




More information about the Python-list mailing list