I try to ad-hoc build up an object, something like:
b = object()
b.a = 0
But no, I can not add an a
to object b
. It's explained here, why that happens. Mainly because object does not have a dict.
But, is there a correct way to ad-hoc construct such an object b
? Maybe instead of object a class that can take properties?
(Before you warn me or advise me to just build a class - yes, I'm aware that this might be the best way to do in many cases. But first, I think, there are cases where an ad-hoc object is useful, maybe just for lazyness in a small code. Second, I also want to understand what's behind the two cases a
and b
.)