Feb. 16, 2021
8:26 a.m.
On Tue, Feb 16, 2021 at 04:43:11PM +0100, Sven R. Kunze wrote:
obj = lambda: 0
to define an anomyous object without the need to define a class first (speaking of brevity).
"Why?", you may ask. The reason is that:
obj = object()
does not create an instance of obj that can be used to add some attributes later on.
>>> from types import SimpleNamespace >>> obj = SimpleNamespace() >>> obj.spam = 1 >>> obj namespace(spam=1) Gives you a nice repr so when you are debugging you can actually see what the object is. -- Steve