如何在类中打印文档字符串
对于函数我可以这样做:
def func():
"""
doc string
"""
print func.__doc__
是否可以用类做同样的事情
class MyClass(object):
def __init__(self):
"""
doc string
"""
i = MyClass()
print i.__doc__
这行不通。它只打印出 None。
我正在编写一个文字游戏,我想使用文档字符串作为对玩家的说明,而不使用 print 命令
谢谢
请您参考如下方法:
它是 None 因为该类没有文档字符串。尝试添加一个:
class MyClass(object):
""" Documentation for MyClass goes here. """
def __init__(self):
"""
doc string
"""
i = MyClass()
print i.__doc__ # same as MyClass.__doc__
