【发布时间】:2010-10-18 13:25:50
【问题描述】:
我有带有对象属性的 Python 类,这些对象属性仅在运行构造函数时声明,如下所示:
class Foo(object):
def __init__(self, base):
self.basepath = base
temp = []
for run in os.listdir(self.basepath):
if self.foo(run):
temp.append(run)
self.availableruns = tuple(sorted(temp))
如果我现在使用 help(Foo) 或尝试在 Sphinx 中记录 Foo,则不会显示 self.basepath 和 self.availableruns 属性。这对我们 API 的用户来说是个问题。
我尝试寻找一种标准方法来确保解析器可以找到(最好是文档字符串)这些“动态声明的”属性,但到目前为止还没有运气。有什么建议?谢谢。
【问题讨论】:
标签: python attributes python-sphinx docstring