Documenting properties

  • Thread starter =?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?=
  • Start date
?

=?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?=

I notice that if I use this syntax:

def classname:
...
##
# closes the database connection and releases the resources.
def close(self):
....

##
# Returns a list of fields
fields = property(....)

then doing:

help (classname)

then the text is listed for the property and the method, whereas if I do
this:

classname.close.__doc__

then nothing is listed, and to get that I have to use the """.."""
syntax to document:

def close(self):
"""closes the datab..."""
....

then classname.close.__doc__ shows the text.

So, my question is, is there a way to get __doc__ support for
properties, in effect, use the """xxx""" syntax for documenting properties.

Is the preferred way to use """xxx""" or # to document ?
Whatever is preferred, what's the upside/downsides of the two beyond
what I just explained?
 
P

Paul McNett

Lasse said:
So, my question is, is there a way to get __doc__ support for
properties, in effect, use the """xxx""" syntax for documenting properties.

Yes, the property() function accepts a doc argument, as in:

property(fget, fset, fdel, doc)

ex:
MyProp = property(_get, _set, None, "This will show up in __doc__")

Is the preferred way to use """xxx""" or # to document ?

# is for source code commenting (audience is the person reading your
code). """x""" is for documenting your API (audience is the person using
your code). They are quite different.

Whatever is preferred, what's the upside/downsides of the two beyond
what I just explained?

Nothing really, but something handy to keep in mind is that the string
literal ("""x""") can be used to block out huge sections of code during
testing, where you'd have to put a # in front of every line otherwise.
 
G

Gerrit Holl

Paul said:
Nothing really, but something handy to keep in mind is that the string
literal ("""x""") can be used to block out huge sections of code during
testing, where you'd have to put a # in front of every line otherwise.

Except, of course, code that contains string literals with triple
quotes. And with a good editor, it's not too difficult to insert a # in
front of hundreds of lines :)%s/^/#/g).

Gerrit.
 

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