Welcome, guest | Sign In | My Account | Store | Cart

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, 8 lines
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

2 comments

Li Daobing 19 years, 7 months ago  # | flag

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

Li Daobing 19 years, 7 months ago  # | flag

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

Created by Dmitry Vasiliev on Thu, 26 Aug 2004 (PSF)
Python recipes (4591)
Dmitry Vasiliev's recipes (9)

Required Modules

  • (none specified)

Other Information and Tasks