【发布时间】:2011-12-03 03:55:30
【问题描述】:
我知道参数可以是任何对象,但对于文档而言,指定您所期望的非常重要。
首先是如何指定像下面这样的参数类型?
-
str(或使用String或string?) intlistdict- 函数()
tuple- 类
MyClass的对象实例
其次,如何指定可以是多种类型的参数,例如可以处理单个参数而不是int或str的函数?
请使用以下示例来演示使用您提出的解决方案记录此内容所需的语法。请注意,希望能够从文档内部超链接对“图像”类的引用。
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
注意,只要能够满足要求,欢迎您建议使用任何文档工具(sphinx、oxygen、...)。
更新:
一般来说,似乎对在 doxygen 中记录参数类型有某种支持。下面的代码有效,但在参数名称中添加了一个烦人的 $(因为它最初是为 php 制作的)。
@param str $arg description
@param str|int $arg description
【问题讨论】:
-
您可以为输入和输出提供的最佳文档是一套通过单元测试,使用
unittestframework。 -
@Johnsyweb 您的链接已损坏docs.python.org/2/library/unittest.html