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:
JavaScript
x
13
13
1
def function1():
2
"""This is my function1 doc !
3
"""
4
pass
5
6
def function2():
7
__doc__ = function1.__doc__
8
pass
9
10
11
>>> help(function2)
12
>>> 'This is my function1 doc !'
13
The last line is what I would like to have.
Thanks ! :)
Advertisement
Answer
you can just assign it at after you define the function.
JavaScript
1
9
1
def function1():
2
"""This is my function1 doc !
3
"""
4
pass
5
6
def function2():
7
pass
8
function2.__doc__ = function1.__doc__
9
Since a function is just an object in python with attributes, you can change the attributes to what you want.