[Python-ideas] A namedtuple literal.
Philipp A.
flying-sheep at web.de
Wed Apr 2 18:34:00 CEST 2014
2014-04-02 17:20 GMT+02:00 Yury Selivanov <yselivanov.ml at gmail.com>:
But when you have a key name defined in a variable, you’ll need to do
key = 'spam'
o = {}
o[key] = 'ham'
Where in Python, you’d simply write {key: ‘ham’}.
So for Python, I think that having unquoted keys in literals is a bad idea.
i totally agree for dicts, but here i don’t. instead i’d require unquoted
keys like in kwargs.
1.
the key here needs to be a valid identifier to be accessed using
namedtuple.key_name.
this could be ensured by the parser if only unquoted keys are allowed,
not if string keys or even variable keys containing arbitrary objects are
allowed
2.
i don’t actually want this to be something with dynamic keys.
it’s supposed to be a namedtuple, and namedtuples are static as well
regarding their keys.
i think it’s best to encourage that functions returning namedtuples only
return one kind of them, so that you can ensure that returnvalue.my_keyworks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140402/3e6442c7/attachment.html>
More information about the Python-ideas
mailing list