docstring reference to another docstring

B

bdb112

A function of the class ClusterSet uses a similar function of the
class Cluster to do most of its work. Its docstring could have so
much in common with that in Cluster that it could be just a line or
two in addition to that of Cluster.

Is there a way for the ClusterSet docstring to tack the Cluster
docstring onto itself, rather than simply saying "See docstring for
Cluster"?
 
C

Chris Rebert

A function of the class ClusterSet uses a similar function of the
class Cluster to do most of its work.  Its docstring could have so
much in common with that in Cluster that it could be just a line or
two in addition to that of Cluster.

Is there a way for the ClusterSet docstring to tack the Cluster
docstring onto itself, rather than simply saying "See docstring for
Cluster"?

#assume Cluster already defined by this point
class ClusterSet(object):
__doc__ = Cluster.__doc__
#rest of class body

Cheers,
Chris
 
B

bdb112

"""" Thanks for the quick reply - I expanded it to a working program,
it seems to do the job and works in my actual code (always good). As
you said, it assumes the called function's class is already defined.
Is there a way around this? (The module was originally ordered
"top-down").
""""

class Cluster():
"""Cluster docs...
"""

def plot():
"""Cluster.plot docs..
"""


class ClusterSet():
"""ClusterSet docs...
"""
__doc__ += "extra" + Cluster.__doc__

def plot():
"""ClusterSet.plot docs..
"""
__doc__ += "this is not what we want, it \
only happens at runtime, and refers to a local
variable"
print("ClusterSet.plot body")

plot.__doc__ += "extra" + Cluster.plot.__doc__


cs=ClusterSet()

print(cs.__doc__)
print(cs.plot.__doc__)
 
C

Chris Rebert

"""" Thanks for the quick reply - I expanded it to a working program,
it seems to do the job and works in my actual code (always good).  As
you said, it assumes the called function's class is already defined.
Is there a way around this? (The module was originally ordered
"top-down").

Not that I know of, it's the nature of Python; though perhaps someone
will chime in. Also, you ought to be subclassing `object` in your
class definitions.

Cheers,
Chris
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top