Re: [Python-Dev] Dict access with double-dot (syntactic sugar)

2011-03-25 Thread Éric Araujo
Again, please keep this thread on python-ideas. If people there agree that this is a very common use case and find a syntax that is not ugly, it will be time to come back to python-dev. Thanks. ___ Python-Dev mailing list Python-Dev@python.org http://ma

Re: [Python-Dev] Dict access with double-dot (syntactic sugar)

2011-03-25 Thread Jameson Quinn
I realized that python already has a way to access the string-based members of a dict without using quotes: def expect_a_chair(chair, **kw): print "Thanks. That chair is %s." % chair if kw: for key, val in kw.iteritems(): print "I wasn't expecting the (%s) %s!" % (val, key) d = json

Re: [Python-Dev] Dict access with double-dot (syntactic sugar)

2011-03-24 Thread Jameson Quinn
> > > You're correct, this is trivial with object_hook. > > >>> class AttrDict(dict): > ... def __getattr__(self, attr): > ... try: > ... return self[attr] > ... except KeyError: > ... raise AttributeError(attr) > ... > >>> import json > >>> obj = json.lo

Re: [Python-Dev] Dict access with double-dot (syntactic sugar)

2011-03-24 Thread Greg Ewing
Santoso Wijaya wrote: `somedict:foo` looks better than `somedict..foo`. Parsing ambiguity: if foo:bar:baz Is that if (foo:bar): baz or if foo: (bar:baz) ? -- Greg ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/m

Re: [Python-Dev] Dict access with double-dot (syntactic sugar)

2011-03-24 Thread Greg Ewing
Jameson Quinn wrote: def fun2(**kw): print kw["argument"] Since this function effectively has a compulsory argument called 'argument', it would be better written def fun2(argument, **kw): print argument or, if the recently-added keyword-only feature is available, def fun2(*, arg

Re: [Python-Dev] Dict access with double-dot (syntactic sugar)

2011-03-24 Thread Santoso Wijaya
I just want to chip in that, as far as syntactic sugar go, `somedict:foo` looks better than `somedict..foo`. 2c... ~/santa On Thu, Mar 24, 2011 at 4:40 AM, Jameson Quinn wrote: > "class attrdict" is a perennial dead-end for intermediate pythonistas who > want to save 3 characters/5 keystrokes

Re: [Python-Dev] Dict access with double-dot (syntactic sugar)

2011-03-24 Thread skip
Greg> Either you have a mostly-fixed set of field names, in which case Greg> you should be using a custom class instead of a dict, or the set Greg> of keys is dynamic, in which case you're mostly indexing with Greg> computed values. Lots of somedict['foo'] appearing is a code G

Re: [Python-Dev] Dict access with double-dot (syntactic sugar)

2011-03-24 Thread Greg Ewing
Jameson Quinn wrote: "class attrdict" is a perennial dead-end for intermediate pythonistas who want to save 3 characters/5 keystrokes for item access. Other languages such as javascript allow "somedict.foo" to mean the same as "somedict['foo']", so why not python? I think the main reason this

Re: [Python-Dev] Dict access with double-dot (syntactic sugar)

2011-03-24 Thread Bob Ippolito
On Thu, Mar 24, 2011 at 11:46 AM, Jameson Quinn wrote: >> >> If you need this for **kw arguments maybe you're not using them right; >> why not name your arguments if you're going to reference them by name? > > Good point. >> >> The JSON use case seems to be driven because this is the way >> JavaSc

Re: [Python-Dev] Dict access with double-dot (syntactic sugar)

2011-03-24 Thread Jameson Quinn
> > > If you need this for **kw arguments maybe you're not using them right; > why not name your arguments if you're going to reference them by name? > Good point. > > The JSON use case seems to be driven because this is the way > JavaScript does things -- they don't distinguish between dicts and

Re: [Python-Dev] Dict access with double-dot (syntactic sugar)

2011-03-24 Thread Maciej Fijalkowski
On Thu, Mar 24, 2011 at 11:50 AM, Guido van Rossum wrote: > On Thu, Mar 24, 2011 at 10:37 AM, Jameson Quinn > wrote: >> OK, fair enough. People don't like this. So let me back up a step. > >> Clearly this is intended for using with things that you get as a dictionary, >> but which really should

Re: [Python-Dev] Dict access with double-dot (syntactic sugar)

2011-03-24 Thread Guido van Rossum
On Thu, Mar 24, 2011 at 10:37 AM, Jameson Quinn wrote: > OK, fair enough. People don't like this. So let me back up a step. > Clearly this is intended for using with things that you get as a dictionary, > but which really should be namespaces. The top two cases of that are parsed > json objects a

Re: [Python-Dev] Dict access with double-dot (syntactic sugar)

2011-03-24 Thread Jameson Quinn
OK, fair enough. People don't like this. So let me back up a step. Clearly this is intended for using with things that you get as a dictionary, but which really should be namespaces. The top two cases of that are parsed json objects and **kw arguments. I suppose that, if I cared to, I could write

Re: [Python-Dev] Dict access with double-dot (syntactic sugar)

2011-03-24 Thread Brian Curtin
On Thu, Mar 24, 2011 at 10:51, Jameson Quinn 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 ha

Re: [Python-Dev] Dict access with double-dot (syntactic sugar)

2011-03-24 Thread Antoine Pitrou
Can this discussion be moved to python-ideas? Thank you. On Thu, 24 Mar 2011 09:51:59 -0600 Jameson Quinn wrote: > Consider: > > def fun1(argument): > print argument1 > > fun1(argument="spam") > > def fun2(**kw): > print kw["argument"] > > Why should I need quotes around "argument

Re: [Python-Dev] Dict access with double-dot (syntactic sugar)

2011-03-24 Thread Jameson Quinn
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

Re: [Python-Dev] Dict access with double-dot (syntactic sugar)

2011-03-24 Thread Jameson Quinn
2011/3/24 Brian Curtin > On Thu, Mar 24, 2011 at 06:40, Jameson Quinn wrote: > >> "class attrdict" is a perennial dead-end for intermediate pythonistas who >> want to save 3 characters/5 keystrokes for item access. Other languages such >> as javascript allow "somedict.foo" to mean the same as "so

Re: [Python-Dev] Dict access with double-dot (syntactic sugar)

2011-03-24 Thread Brian Curtin
On Thu, Mar 24, 2011 at 06:40, Jameson Quinn wrote: > "class attrdict" is a perennial dead-end for intermediate pythonistas who > want to save 3 characters/5 keystrokes for item access. Other languages such > as javascript allow "somedict.foo" to mean the same as "somedict['foo']", so > why not py

Re: [Python-Dev] Dict access with double-dot (syntactic sugar)

2011-03-24 Thread Dirkjan Ochtman
On Thu, Mar 24, 2011 at 12:40, Jameson Quinn wrote: > "class attrdict" is a perennial dead-end for intermediate pythonistas who > want to save 3 characters/5 keystrokes for item access. Other languages such > as javascript allow "somedict.foo" to mean the same as "somedict['foo']", so > why not py

[Python-Dev] Dict access with double-dot (syntactic sugar)

2011-03-24 Thread Jameson Quinn
"class attrdict" is a perennial dead-end for intermediate pythonistas who want to save 3 characters/5 keystrokes for item access. Other languages such as javascript allow "somedict.foo" to mean the same as "somedict['foo']", so why not python? Well, there are a number of reasons why not, beginning