最後三行有什麼問題?使用object時的AttributeError .__ setattr__
class FooClass(object):
pass
bar1 = object()
bar2 = object()
bar3 = object()
foo1 = FooClass()
foo2 = FooClass()
foo3 = FooClass()
object.__setattr__(foo1,'attribute','Hi')
foo2.__setattr__('attribute','Hi')
foo3.attribute = 'Hi'
object.__setattr__(bar1,'attribute','Hi')
bar2.attribute = 'Hi'
bar3.attribute = 'Hi'
我需要具有單個屬性(類似foo)的對象我應該定義一個類(如FooClass)只是呢?
l = list(); l.attr = 7; AttributeError ...我想你是對的! – jimifiki