May-01-2017, 01:36 PM
Output:>>> x.name = 'Fred'
>>> fred = object()
>>> fred.name = 'Fred'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'object' object has no attribute 'name'
>>> class Thing(object):
... pass
...
>>> george = Thing()
>>> george.name = 'George'
>>> george.name
'George'
So, something in the object class prevents attributes being assigned on the fly. I'm not worried about that. What confuses me is the Thing class, which inherits from object without overriding anything. Why doesn't it inherit the blocking of attributes being assigned on the fly?
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures