Re: Using object as a class

2018-03-26 Thread Steven D'Aprano
On Mon, 26 Mar 2018 07:31:06 -0500, D'Arcy Cain wrote: > Is this behaviour (object not quite like a class) documented anywhere? It's exactly like a class. It's an immutable class. You are making assumptions about what classes must be able to do. > Does anyone know the rationale for this if

Re: Using object as a class

2018-03-26 Thread Paul Moore
In fact, object acts just like a user-defined class, with __slots__ set to empty: >>> class MyObj(object): ... __slots__ = () ... >>> o = MyObj() >>> o.x = 3 Traceback (most recent call last): File "", line 1, in AttributeError: 'MyObj' object has no attribute 'x' See

Using object as a class

2018-03-26 Thread D'Arcy Cain
It's called a super class but it doesn't quite work like a normal class. >>> OBJ = object() >>> OBJ.x = 3 Traceback (most recent call last): File "", line 1, in AttributeError: 'object' object has no attribute 'x' I can fix this by creating a NULL class. >>> class NullObject(object): pass