Accessing docstrings at runtime?

K

Kenneth Love

How do I print the docstring for a class property?

When I run the code below, I get the docstring for the string module
and not the one I set for the property.

---------------------------------------------
# NOTE: Found in Python docs defining built-in functions (such as
# property()). FIXED: Bug in getx, setx, and delx where "__x"
# was misreferenced as "_x".
class C(object):
def __init__(self):
self.__x = None
def getx(self):
return self.__x
def setx(self, value):
self.__x = value
def delx(self):
del self.__x
x = property(getx, setx, delx, "I'm the 'x' property.")

if __name__ == "__main__"
y = C()
y.x = 'test'
print y.x
print y.x.__doc__
---------------------------------------------

I get the following output:

---------------------------------------------
test
str(object) -> string

Return a nice string representation of the object.
If the argument is a string, the return value is the same object.
---------------------------------------------

What am I doing wrong?

adTHANKSvance,
Kenneth Love

P.S. If I want a docstring and I do not want a delete function,
do I just pass 'None' (minus quotes) for that parameter?

--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Kenneth Love | Oklahoma Tax Commission
DP Programmer/Analyst | Information Technology
(405) 522 - 5864 | http://www.tax.ok.gov/
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top