我知道参数可以是任何对象,但对于文档而言,指定您期望的内容非常重要.
首先是如何指定下面的参数类型?
str(或使用String或string?)intlistdicttupleMyClass第二,如何指定可以是多种类型的参数,比如可以处理单个参数的函数,int或者可以是str?
请使用以下示例演示使用您提出的解决方案记录此文档所需的语法.请注意,希望能够从文档内部超链接对"Image"类的引用.
def myMethod(self, name, image):
"""
Does something ...
name String: name of the image
image Image: instance of Image Class or a string indicating the filename.
Return True if operation succeeded or False.
"""
return True
Run Code Online (Sandbox Code Playgroud)
请注意,只要能够处理要求,欢迎您使用任何文档工具(sphinx,oxygen,...).
它表示在doxygen中记录参数类型有一些支持.一般.下面的代码可以工作但是会给param名称添加一个烦人的$(因为它最初是为php制作的).
@param str $arg description
@param str|int $arg description
Run Code Online (Sandbox Code Playgroud)
Ton*_*ony 13
有一个更好的办法.我们用
def my_method(x, y):
"""
my_method description
@type x: int
@param x: An integer
@type y: int|string
@param y: An integer or string
@rtype: string
@return: Returns a sentence with your variables in it
"""
return "Hello World! %s, %s" % (x,y)
Run Code Online (Sandbox Code Playgroud)
而已.在PyCharm IDE中,这有很大帮助.它就像一个魅力;-)
小智 6
您需要在Doxygen的Python文档字符串的开头添加感叹号才能正确解析它.
def myMethod(self, name, image):
"""!
Does something ...
@param name String: name of the image
@param image Image: instance of Image Class or a string indicating the filename.
@return Return True if operation succeeded or False.
"""
return True
Run Code Online (Sandbox Code Playgroud)
如果使用 Python 3,您可以使用PEP 3107中描述的函数注释。
def compile(
source: "something compilable",
filename: "where the compilable thing comes from",
mode: "is this a single statement or a suite?"):
Run Code Online (Sandbox Code Playgroud)
另请参见函数定义。
| 归档时间: |
|
| 查看次数: |
20595 次 |
| 最近记录: |