2 ms·
named tuples are classes, but they use __slots__ so they are sealed to extension thus using less memory. Take a look at the `namedtuple` source, it is a fun lit
by sitkack 13y ago
named tuples are classes, but they use __slots__ so they are sealed to extension thus using less memory. Take a look at the `namedtuple` source, it is a fun little bit of metaprogramming.
http://dev.svetlyak.ru/using-slots-for-optimisation-in-python-en/ http://dev.svetlyak.ru/using-slots-for-optimisation-in-pytho...
http://hg.python.org/releasing/2.7.6/file/ba31940588b6/Lib/collections.py#l228 http://hg.python.org/releasing/2.7.6/file/ba31940588b6/Lib/c...
I am wrong. namedtuple does NOT using slots. weird, wonder why?
Because it directly subclasses `tuple`
point = namedtuple("Point","x y z",verbose=True)
http://blip.tv/pycon-us-videos-2009-2010-2011/pycon-2011-fun-with-python-s-newer-tools-4901215 http://blip.tv/pycon-us-videos-2009-2010-2011/pycon-2011-fun...