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

Steven D'Aprano steve at pearwood.info
Wed Jul 26 20:38:07 EDT 2017

On Thu, Jul 27, 2017 at 11:46:45AM +1200, Greg Ewing wrote:
> Nick Coghlan wrote:
> >The same applies to the ntuple concept, expect there it's the fact
> >that it's a *tuple* that conveys the "order matters" expectation.
> That assumes there's a requirement that it be a tuple in
> the first place. I don't see that requirement in the use
> cases suggested here so far.

This is an excellent point. Perhaps we should just find a shorter name 
for SimpleNamespace and promote it as the solution.

I'm not sure about other versions, but in Python 3.5 it will even save 
memory for small records:

py> from types import SimpleNamespace
py> spam = SimpleNamespace(flavour='up', charge='1/3')
py> sys.getsizeof(spam)
py> from collections import namedtuple
py> eggs = namedtuple('record', 'flavour charge')(charge='1/3', flavour='up')
py> sys.getsizeof(eggs)
py> sys.getsizeof(('up', '1/3'))


More information about the Python-ideas mailing list