[Python-ideas] A namedtuple literal.

Yury Selivanov yselivanov.ml at gmail.com
Wed Apr 2 17:20:18 CEST 2014


On 2014-04-02, 12:40 AM, Eric Snow wrote:
> (Inspired by https://mail.python.org/pipermail/python-ideas/2010-October/008532.html)
>
> (color: c, position: p)
While it looks extremely neat, there is one design flaw that is shared 
with JavaScript's object literals.

In JS, if you want to define a simple object, you can write it in two ways:

     {'spam': 'ham'}

or

     {spam: 'ham'}

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.

Yury


More information about the Python-ideas mailing list