我们来举一个例子:
class Apple(object): """ This is an Apple Class""" def get_color(self): """ Get the Color of Apple. get_color(self) -> str """ return "red"
在python terminal输入
>>> from CallDemo import Apple >>> help(Apple) Help on class Apple in module CallDemo: class Apple(__builtin__.object) | This is an Apple Class | | Methods defined here: | | get_color(self) | Get the Color of Apple. | get_color(self) -> str | | ---------------------------------------------------------------------- | Data descriptors defined here: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined)
例如,我们添加了文档测试内容后如下所示:
class Apple(object): """ This is an Apple Class Example: >>> apple = Apple() >>> apple.get_color() 'red' >>> apple.set_count(20) >>> apple.get_count() 400 """ def get_color(self): """ Get the Color of Apple. get_color(self) -> str """ return "red" def set_count(self, count): self._count = count def get_count(self): return self._count * self._countif __name__ == '__main__': import doctest
doctest.testmod()
由于我们写了
if __name__ == '__main__': import doctest doctest.testmod()
以上就是python学习笔记-为自定义类或者函数编写help文档,以及进行文档测试的内容,更多相关内容请关注PHP中文网(HdhCmsTestgxlcms测试数据)!
查看更多关于python学习笔记-为自定义类或者函数编写help文档,以及进行文档测试的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did86234