Reputation: 23
Does anybody know if it is possible to link a function1.__doc__
to a function2.__doc__
without writting it 2 times ?
For example I tried something like:
def function1():
"""This is my function1 doc !
"""
pass
def function2():
__doc__ = function1.__doc__
pass
>>> help(function2)
>>> 'This is my function1 doc !'
The last line is what I would like to have.
Thanks ! :)
Upvotes: 2
Views: 75
Reputation: 255
So this is what you need to do:
def function1():
pass
def function2():
pass
function1.__doc__ = function2.__doc__ = """This is my function1 doc !"""
So now if you print the docstring of any function of these two, the output will be :
This is my function1 doc !
Upvotes: 0
Reputation: 520
you can just assign it at after you define the function.
def function1():
"""This is my function1 doc !
"""
pass
def function2():
pass
function2.__doc__ = function1.__doc__
Since a function is just an object in python with attributes, you can change the attributes to what you want.
Upvotes: 2