简体   繁体   English

如何在 Python 文档字符串中添加链接?

[英]How to add link in Python docstring?

I have a function in python 3.x我在 python 3.x 中有一个函数

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

I want to add a hyperlink to 'here' to point to a website.我想添加一个指向“这里”的超链接以指向一个网站。 How can I do that without installing external plugin?在不安装外部插件的情况下如何做到这一点?

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. docstring 只是一个字符串,所以没有超链接。 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 eg html.有自动文档构建器可以根据您的代码和文档字符串(例如 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.如果您只有代码,那么只需将 url 添加为字符串即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM