[Python-Dev] Impact of Namedtuple on startup time (original) (raw)
Giampaolo Rodola' g.rodola at gmail.com
Mon Jul 17 17:09:16 EDT 2017
- Previous message (by thread): [Python-Dev] Impact of Namedtuple on startup time
- Next message (by thread): [Python-Dev] Impact of Namedtuple on startup time
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Mon, Jul 17, 2017 at 11:07 PM, Petr Viktorin <encukou at gmail.com> wrote:
On 07/17/2017 10:31 PM, Giampaolo Rodola' wrote:
I completely agree. I love namedtuples but I've never been too happy about the additional overhead vs. plain tuples (both for creation and attribute access times), to the point that I explicitly avoid to use them in certain circumstances (e.g. a busy loop) and only for public end-user APIs returning multiple values.
To be entirely honest, I'm not even sure why they need to be forcefully declared upfront in the first place, instead of just having a first-class function (builtin?) written in C: >>> ntuple(x=1, y=0) (x=1, y=0) ...or even a literal as in: >>> (x=1, y=0) (x=1, y=0) Most of the times this is what I really want: quickly returning an anonymous tuple with named attributes and nothing else, similarly to os.times() & others. [...] It seems that you want
types.SimpleNamespace(x=1, y=0)
.
That doesn't support indexing (obj[0]).
-- Giampaolo - http://grodola.blogspot.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20170717/2b92d2c7/attachment.html>
- Previous message (by thread): [Python-Dev] Impact of Namedtuple on startup time
- Next message (by thread): [Python-Dev] Impact of Namedtuple on startup time
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]