Accessing docstrings at runtime?

Discussion in 'Python' started by Kenneth Love, Aug 29, 2007.

  1. Kenneth Love

    Kenneth Love Guest

    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/
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    Kenneth Love, Aug 29, 2007
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nuff Said
    Replies:
    0
    Views:
    433
    Nuff Said
    May 5, 2004
  2. Sridhar R

    docstrings vs language comments

    Sridhar R, Jun 20, 2004, in forum: Python
    Replies:
    2
    Views:
    765
    Rick L. Ratzel
    Jun 21, 2004
  3. Craig Ringer

    Unicode docstrings in PyMethodDef?

    Craig Ringer, Dec 8, 2004, in forum: Python
    Replies:
    0
    Views:
    342
    Craig Ringer
    Dec 8, 2004
  4. Craig Ringer

    Re: Unicode docstrings in PyMethodDef?

    Craig Ringer, Dec 10, 2004, in forum: Python
    Replies:
    1
    Views:
    353
    =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=
    Dec 10, 2004
  5. Steven Bethard

    duplicate docstrings

    Steven Bethard, Feb 18, 2005, in forum: Python
    Replies:
    2
    Views:
    290
    Felix Wiemann
    Feb 19, 2005
Loading...

Share This Page