pythonhyperlinkdocumentationdocstring

How to add link in Python docstring?


I have a function in python 3.x

def foo():
"""Lorem ipsum for more info, see here""

I want to add a hyperlink to 'here' to point to a web site. How can I do that without installing external plugin?


Solution

  • Just add the link as a string into the docstring, like so:

    def foo():
        """Lorem ipsum for more info, see here: www.myfancydocu.com""
    

    The doctring is just a string, so there is no Hyperlink. But anyone that wants to look at the website can just copy the link.

    There are automatic documentation-builders that build a documentation out of your code and docstrings in e.g. html. Those can probably add hyperlinks to the documentation with a specific syntax, but that syntax then depends on which documentation-builder you use. If you only have your code, then just adding the url as a string is all you can do.