[Tutor] assigning __doc__ strings (manually)

Hans Fangohr H.FANGOHR at soton.ac.uk
Wed Sep 1 17:21:17 CEST 2004


I am facing the following problem and would like some advise:

I have two functions, say for simplicity, real_f and f:

def real_f(x):
     """this is my doc-string"""
     return x**2, x**3

def f(x):
     return real_f(x)[0]

The actual work is done in real_f() and some users might be interested
in x**3 and x**2. However, most of the users will only care about x**2
and are happy to use the function f() for this.

(In the actual program I am working on there is of course more work
involved than just computing x**2 and x**3 ...)

Since the main computation is done in real_f(), I thought I'd create a
doc-string in real_f() that explains the computation being implemented
etc (as done above).

The function f() does basically the same as real_f() and should
provide the same docstring as real_f(). To avoid copying the
information, I thought I could do this when defining f():

def f(x):

     return real_f(x)[0]

which -- I was hoping -- would provide real_f.__doc__ in
f.__doc__. However, f.__doc__ is None.

Can this be solved? Or am I on the wrong track here?  Looking forward
to hearing from you,


More information about the Tutor mailing list