3 Suggestions to Make Python Easier For Children
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Sat Aug 2 11:43:18 EDT 2014
Marko Rauhamaa wrote:
> Expanding #3:
>
> >>> o = object()
> >>> o.x = 3
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> AttributeError: 'object' object has no attribute 'x'
>
> Why?
There are two intended uses for object and its instances:
- as the base class for all other classes;
- instances can be used as featureless sentinel objects where
only identity matters.
If you need instances which carry state, then object is the wrong class.
--
Steven
More information about the Python-list
mailing list