[Python-Dev] PEP 450 adding statistics module (original) (raw)

Antoine Pitrou solipsis at pitrou.net
Fri Aug 16 10:51:26 CEST 2013


On Fri, 16 Aug 2013 12:44:54 +1000 Steven D'Aprano <steve at pearwood.info> wrote:

On 16/08/13 04:10, Eric V. Smith wrote:

> I agree with Mark: the proposed median, median.low, etc., doesn't feel > right. Is there any example of doing this in the stdlib? The most obvious case is datetime: we have datetime(), and datetime.now(), datetime.today(), and datetime.strftime(). The only API difference between it and median is that datetime is a type and median is not, but that's a difference that makes no difference:

Of course it does. The datetime classmethods return datetime instances, which is why it makes sense to have them classmethods (as opposed to module functions).

The median functions, however, don't return median instances.

My preference is to make median a singleton instance with a call method, and the other flavours regular methods. Although I don't like polluting the global namespace with an unnecessary class that will only be instantiated once, if it helps I can do this:

class Median: def call(self, data): ... def low(self, data): ... median = Median() If that standard OOP design is unacceptable, I will swap the dots for underscores, but I won't like it.

Using "OOP design" for something which is conceptually not OO (you are just providing callables in the end, not types and objects: your _Median "type" doesn't carry any state) is not really standard in Python. It would be in Java :-)

Regards

Antoine.



More information about the Python-Dev mailing list