What is NotImplemented ?

Alexandre Fayolle alf at logilab.fr
Mon Apr 29 04:57:40 EDT 2002


Dans l'article <lkn0vq34fi.fsf at pc150.maths.bris.ac.uk>, Michael Hudson a écrit :
> Alexandre Fayolle <alf at logilab.fr> writes:
> 
>> A quick question, here. What is the built in NotImplemented object? 
>> And what can you do with it? I thought I could raise it as an 
>> exception, but this is not the case (I use NotImplementedError instead).
> 
> I think you can return it from implementations of, say, __add__ to
> mean roughly "I don't know what to do here".
<snip>
> Returning NotImplemented from the __add__ makes Python go off and call
> the __radd__ method.

Ahah! Thanks a lot. 

The relevant documentation is in the Python Reference Manual, §3.2,
while I was looking for it in the library reference. 

Alexandre Fayolle
-- 
LOGILAB, Paris (France).
http://www.logilab.com   http://www.logilab.fr  http://www.logilab.org
Narval, the first software agent available as free software (GPL).



More information about the Python-list mailing list