On Thu, Mar 24, 2011 at 10:51, Jameson Quinn <jameson.qu...@gmail.com>wrote:

> Consider:
>
> def fun1(argument):
>     print argument1
>
> fun1(argument="spam")
>
> def fun2(**kw):
>     print kw["argument"]
>
> Why should I need quotes around "argument" in just one of those places?
> What if I left them off, and there happened to be a global variable named
> "argument"? Why shouldn't I be able to say:
>
> def fun2(**kw):
>     print kw..argument
>
> (in real life, there would be a try... except block in case there was no
> argument, I'm just showing the simplest case here.)
>

I can certainly see use cases for this, but none generic enough for the
standard library.

Let's take the configparser module for example: in 3.2 ConfigParser objects
can now be accessed like dictionaries. Looking at the examples in the
documentation [0], an immediate problem comes to mind:

    print(config..bitbucket.org..user)
    *boom*

If you're going to be doing attribute access, it's likely that you know the
name of the attribute -- you wrote the code knowing what to expect in the
first place. If you know the names of the attributes you're going to be
dealing with, why not just store them in a class, or even a class with
__slots__ defined for each attribute?

The double-dot notation will only work when you already know the key. When
iterating over keys, you're going to resort back to dict[key] or
getattr(dict, key) to get the value.

In the end, it's syntactic sugar for a limited set of applicable cases.



[0] http://docs.python.org/release/3.2/library/configparser
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to