<div class="gmail_quote">On Thu, Mar 24, 2011 at 10:51, Jameson Quinn <span dir="ltr">&lt;<a href="mailto:jameson.quinn@gmail.com">jameson.quinn@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Consider:<div><br></div><div>def fun1(argument):</div><div>    print argument1</div><div><br></div><div>fun1(argument=&quot;spam&quot;)</div><div><br></div><div>def fun2(**kw):</div><div>    print kw[&quot;argument&quot;]</div>


<div><br></div><div>Why should I need quotes around &quot;argument&quot; in just one of those places? What if I left them off, and there happened to be a global variable named &quot;argument&quot;? Why shouldn&#39;t I be able to say:</div>


<div><br></div><div>def fun2(**kw):</div><div>    print kw..argument</div><div><br></div><div>(in real life, there would be a try... except block in case there was no argument, I&#39;m just showing the simplest case here.)</div>
</blockquote><div><br></div><div>I can certainly see use cases for this, but none generic enough for the standard library.</div><div><br></div><div>Let&#39;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:</div>
<div><br></div><div>    print(config..bitbucket.org..user)</div><div>    *boom*</div><div><br></div><div>If you&#39;re going to be doing attribute access, it&#39;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&#39;re going to be dealing with, why not just store them in a class, or even a class with __slots__ defined for each attribute?</div>
<div><br></div><div>The double-dot notation will only work when you already know the key. When iterating over keys, you&#39;re going to resort back to dict[key] or getattr(dict, key) to get the value.</div><div><br></div>
<div>In the end, it&#39;s syntactic sugar for a limited set of applicable cases.</div><div><br></div><div><br></div><div><br></div><div>[0] <a href="http://docs.python.org/release/3.2/library/configparser">http://docs.python.org/release/3.2/library/configparser</a></div>
</div>