[Python-ideas] namedtuple literals [Was: RE a new namedtuple]

Mike Miller python-ideas at mgmiller.net
Wed Jul 26 23:23:53 EDT 2017

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.


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.

More information about the Python-ideas mailing list