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 enough to change the python semantic ? Or simply is
>> it a good idea ?
> 
> Changing python semantics for something like this is nuts.  Allowing
> passing a callable (sort of like re.sub allows) makes a certain amount
> of sense:
> 
>    d.get('a', default=f)


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': 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 defaultdict instead.


-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to