Many times in the olden days when I needed a bag o' attributes to be passed around like a struct I'd make a dummy class, then instantiate it. (A lot harder than the javascript equivalent.)

Unfortunately, the modern Python solution:

    from types import SimpleNamespace as ns

is only a few characters shorter. Perhaps a 'ns()' or 'bag()' builtin alias could fit the bill.

Another idea I had not too long ago, was to let an object() be writable, then no further changes would be necessary.

-Mike


On 2017-07-26 17:38, Steven D'Aprano wrote:
This is an excellent point. Perhaps we should just find a shorter name
for SimpleNamespace and promote it as the solution.

_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to