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
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/YVTKNC6GEJS2RE2ZCU4YRQ7NVG4AFILY/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to