Oct-19-2018, 03:12 AM
If you just want something you can assign any attribute to, subclass object:
>>> class Foo(object): ... pass ... >>> foo = Foo() >>> foo.bar = 5 >>> foo.bar 5Oddly enough, this doesn't work with object itself:
>>> obj = object() >>> obj.bar = 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'object' object has no attribute 'bar'Another handy one creates and assigns any attributes you pass it:
class Morphling(object): def __init__(self, **kwargs): self.__dict__.update(kwargs)
>>> morph = Morphling(foo = 5) >>> morph.foo 5I use that type of class to make dummy objects for unit testing.
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