ActiveState Code

Recipe 302036: Decorator for appending author info to the function docstring (Python 2.4)


Some examples:

<pre>

>>> @author("John")
... @author("Paul")
... def test():
...     "Test function"
...
>>> help(test)
Help on function test in module __main__:

test() Author: John Author: Paul Test function </pre>

Python
1
2
3
4
5
6
7
8
def author(name):
    def setauthor(func):
        author = "Author: %s" % name
        if func.__doc__:
            author += "\n" + func.__doc__
        func.__doc__ = author
        return func
    return setauthor

Comments

  1. 1. At 10:07 p.m. on 27 aug 2004, Li Daobing said:

    This python is not simple enough. Python should be simple. This python code is not simple enough.

  2. 2. At 10:09 p.m. on 27 aug 2004, Li Daobing said:

    I add the above comment to "Decorator for appending author info to the function docstring (Python 2.4)", but why it's here?

Sign in to comment