None versus MISSING sentinel -- request for design feedback

Rob Williscroft rtw at rtw.me.uk
Fri Jul 15 03:43:57 EDT 2011


Steven D'Aprano wrote in news:4e1fd009$0$29986$c3e8da3
$5496439d at news.astraweb.com in gmane.comp.python.general:

> I'm designing an API for some lightweight calculator-like statistics
> functions, such as mean, standard deviation, etc., and I want to support
> missing values. Missing values should be just ignored. E.g.:
> 
> mean([1, 2, MISSING, 3]) => 6/3 = 2 rather than 6/4 or raising an error.

If you can't make your mind up then maybe you shouldn't:

MISSING = MissingObject()
def mean( sequence, missing = MISSING ):
  ...

Rob.




More information about the Python-list mailing list