我想在列表中插入一个对象,但出现了一个错误:
Archive.insertdoc(d)
TypeError: insertdoc() missing 1 required positional argument: 'd'
这是我的主要模块:
doc = Document(name, author, file)
Archive.insertdoc(doc)
Archive
模块:
def __init__(self):
self.listdoc = []
def insertdoc(self, d):
self.listdoc.append(d)
看起来
Archive.insertdoc
是类Archive
的实例方法。也就是说,它必须在Archive
的实例上调用:您需要为
Archive
类创建一个实例;您正在访问unbound方法。你知道吗这应该起作用:
假设您有:
如果将两个函数放在模块级别,则不能在函数中有
self
引用并将其绑定到模块;函数不绑定到模块。你知道吗如果您的存档应该是应用程序的全局存档,请在模块中创建
Archive
类的单个实例,并仅使用该实例。你知道吗相关问题 更多 >
编程相关推荐