例如:
class Foo:
def __init__(self):
self.bar = ["baz", "qux", "quux", "quuz", "corge", "grault", "garply", "waldo", "fred", "plugh", "xyzzy", "thud"]
如何调用附加在Foo().append()
上的Foo().bar
?
Ex:
x = Foo()
x.append("asd")
# What I want to happen:
# self.bar now is [..., "asd"]
# What actually happens:
# AttributeError: 'Foo' object has no attribute 'append'
这可能吗?
我自己添加了append
函数:
# ... in the Foo() class
def append(self, value):
return self.bar.append(value)