Re: short path evaluation, why is f() called here: dict(a=1).get('a', f())

2008-01-15 Thread Paul Rubin
aspineux <[EMAIL PROTECTED]> writes: > Nice idea, but if I want args I need to write it like that: > > x=d.get('a', defaultfunc=f, funcargs=(1,2,3)) Yeah, that looks good. The default arg to f should be the key being looked up. -- http://mail.python.org/mailman/listinfo/python-list

Re: short path evaluation, why is f() called here: dict(a=1).get('a', f())

2008-01-15 Thread aspineux
On Jan 14, 8:07 pm, aspineux <[EMAIL PROTECTED]> wrote: > On Jan 14, 7:49 pm, "Chris Mellon" <[EMAIL PROTECTED]> wrote: > > > On Jan 14, 2008 12:39 PM, aspineux <[EMAIL PROTECTED]> wrote: > > > > This append in both case > > > > dict(a=1).get('a', f()) > > > dict(a=1).setdefault('a', f()) > > > > T

Re: short path evaluation, why is f() called here: dict(a=1).get('a', f())

2008-01-15 Thread aspineux
On Jan 15, 12:15 am, Paul Rubin wrote: > Steven D'Aprano <[EMAIL PROTECTED]> writes: > > map = {'a': Aclass, 'b': Bclass, 'c': Cclass} > > class_ = map.get(astring, default=Zclass) > > > The result I want is the class, not the result of calling the class > > (which would

Re: short path evaluation, why is f() called here: dict(a=1).get('a', f())

2008-01-14 Thread Steven D'Aprano
On Mon, 14 Jan 2008 15:15:28 -0800, Paul Rubin wrote: > Steven D'Aprano <[EMAIL PROTECTED]> writes: >> map = {'a': Aclass, 'b': Bclass, 'c': Cclass} class_ = map.get(astring, >> default=Zclass) >> >> The result I want is the class, not the result of calling the class >> (which would be an instanc

Re: short path evaluation, why is f() called here: dict(a=1).get('a', f())

2008-01-14 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes: > map = {'a': Aclass, 'b': Bclass, 'c': Cclass} > class_ = map.get(astring, default=Zclass) > > The result I want is the class, not the result of calling the class > (which would be an instance). If I wanted the other semantics, I'd be > using defaultd

Re: short path evaluation, why is f() called here: dict(a=1).get('a', f())

2008-01-14 Thread Tim Chase
> But how can Python determine when you want the result to be *the > callable* and when you want it to be *the result of calling the > callable*? > > Functions and other callables are first-class objects, and it is quite > reasonable to have something like this: > > map = {'a': Aclass, 'b': B

Re: short path evaluation, why is f() called here: dict(a=1).get('a', f())

2008-01-14 Thread Steven D'Aprano
On Mon, 14 Jan 2008 12:08:52 -0800, Paul Rubin wrote: > aspineux <[EMAIL PROTECTED]> writes: >> Yes, I missed 'get' and 'setdefault' are functions :-) Then why not >> some new semantic >> >> d.get('a', f()) --> d['a', f()] >> d.setdefault('a', f()) --> d['a'=f()] >> >> Is is a good idea enou

Re: short path evaluation, why is f() called here: dict(a=1).get('a', f())

2008-01-14 Thread Paul Rubin
aspineux <[EMAIL PROTECTED]> writes: > Yes, I missed 'get' and 'setdefault' are functions :-) > Then why not some new semantic > > d.get('a', f()) --> d['a', f()] > d.setdefault('a', f()) --> d['a'=f()] > > Is is a good idea enough to change the python semantic ? > Or simply is it a good idea

Re: short path evaluation, why is f() called here: dict(a=1).get('a', f())

2008-01-14 Thread aspineux
On Jan 14, 7:49 pm, "Chris Mellon" <[EMAIL PROTECTED]> wrote: > On Jan 14, 2008 12:39 PM, aspineux <[EMAIL PROTECTED]> wrote: > > > > > This append in both case > > > dict(a=1).get('a', f()) > > dict(a=1).setdefault('a', f()) > > > This should be nice if f() was called only if required. > > Think a

Re: short path evaluation, why is f() called here: dict(a=1).get('a', f())

2008-01-14 Thread Neil Cerutti
On Jan 14, 2008 1:39 PM, aspineux <[EMAIL PROTECTED]> wrote: > > This append in both case > > dict(a=1).get('a', f()) > dict(a=1).setdefault('a', f()) > > This should be nice if f() was called only if required. Shortcomings of those methods is probably why collections.defaultdict is so popular. >

Re: short path evaluation, why is f() called here: dict(a=1).get('a', f())

2008-01-14 Thread Chris Mellon
On Jan 14, 2008 12:39 PM, aspineux <[EMAIL PROTECTED]> wrote: > > This append in both case > > dict(a=1).get('a', f()) > dict(a=1).setdefault('a', f()) > > This should be nice if f() was called only if required. > Think about the change to Python semantics that would be required for this to be tru

short path evaluation, why is f() called here: dict(a=1).get('a', f())

2008-01-14 Thread aspineux
This append in both case dict(a=1).get('a', f()) dict(a=1).setdefault('a', f()) This should be nice if f() was called only if required. Regards. -- http://mail.python.org/mailman/listinfo/python-list