Pythonic way for missing dict keys

Bruno Desthuilliers bruno.42.desthuilliers at wtf.websiteburo.oops.com
Thu Aug 2 06:23:54 EDT 2007


Alex Popescu a écrit :
> Bruno Desthuilliers <bdesth.quelquechose at free.quelquepart.fr> wrote in
> news:46b0ed0b$0$2257$426a74cc at news.free.fr: 
(snip)
>> if hasattr(obj, '__call__'):
>>    # it's a callable
>>
>> but I don't find it so Pythonic to have to check for a __magic__
>> method. 
> 
> It looks like Python devs have decided it is Pythonic, because it is 
> already in the PEP. 

I do know, and I disagree with this decision.

FWIW, repr(obj) is mostly syntactic sugar for obj.__repr__(), 
getattr(obj, name) for obj.__getattr__(name), type(obj) for 
obj.__class__  etc... IOW, we do have a lot of builtin functions that 
mostly encapsulate calls to __magic__ methods, and I definitively don't 
understand why this specific one (=> callable(obj)) should disappear. I 
usually have lot of respect for Guido's talent as a language designer 
(obviously since Python is still MFL), but I have to say I find this 
particular decision just plain stupid. Sorry.



More information about the Python-list mailing list