471,325 Members | 1,421 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,325 software developers and data experts.

Accessing docstrings at runtime?

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

Aug 29 '07 #1
0 776

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Sridhar R | last post: by
reply views Thread by Craig Ringer | last post: by
2 posts views Thread by Steven Bethard | last post: by
reply views Thread by Michael Muller | last post: by
6 posts views Thread by Kamilche | last post: by
reply views Thread by Edward Loper | last post: by
12 posts views Thread by jelle | last post: by
reply views Thread by tjhnson | last post: by
6 posts views Thread by Steve Brown | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.