使用成员变量时的Python AttributeError

2024-05-19 21:55:37 发布

您现在位置:Python中文网/ 问答频道 /正文

Python在访问变量时抛出AttributeError时遇到了一个问题。在

下面是代码,为了清楚起见,对其进行了修订。在

class mycollection(object):
    """
    Collection of stuff. 
    """
    #"compile-time" define class variables.
    __slots__ = ["stuff_list"]

    def __init__(self):
        self.stuff_list = []

    def add_stuff(self, stuff):
        self.stuff_list.append(stuff)


#later on..
collection = mycollection()
stuff = stuff()
collection.add_stuff(stuff)

正在生成此错误。在

^{pr2}$

通过检查documentation,我不明白为什么会出现这个错误。在


Tags: of代码selfaddobjectdef错误list