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
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
>
>
> 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
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
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
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
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
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
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
>
>
> 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
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
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
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
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
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
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
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
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
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
"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
20 matches
Mail list logo