Using object as a class
D'Arcy Cain
darcy at VybeNetworks.com
Mon Mar 26 08:31:06 EDT 2018
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 "<stdin>", line 1, in <module>
AttributeError: 'object' object has no attribute 'x'
I can fix this by creating a NULL class.
>>> class NullObject(object): pass
...
>>> OBJ = NullObject()
>>> OBJ.x = 3
>>> OBJ.x
3
>>>
Is this behaviour (object not quite like a class) documented anywhere?
Does anyone know the rationale for this if any?
In case anyone wants to know why I am doing this, sometimes I simply
want an object to hold values that I can pass around. I don't need
methods and I don't always know what variables I am going to need.
And yes, I know that dict is the usual way to do this.
--
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:darcy at Vex.Net VoIP: sip:darcy at VybeNetworks.com
More information about the Python-list
mailing list