Subclassing the min() build-in function?

Bernhard Herzog bh at intevation.de
Wed Nov 6 12:23:00 EST 2002


oracle_vs_ms at yahoo.dk (Peter Lorenzen) writes:

> Hi,
> 
> I am using Jython to calculate a string like this:  "2+3+min(1,2,3)"
> from my Java pro-gram. This works beautifully. But my problem is that
> if a user wants to calculate min(1) Python considers this an error. I
> want it to return 1. If I could figure out how to subclass the min
> function, so when it was called with one parameter I just returned
> this parame-ter, and otherwise returned the super min function.

I don't know how Jython implements min, but in CPython min can be called
with one parameter as long as that parameter is a sequence (I think an
iterator also works)

>>> min([1,2,3])
1

Your proposal woule mean that it returns the list which obviously is not
backwards compatible.

   Bernhard

-- 
Intevation GmbH                                 http://intevation.de/
Sketch                                 http://sketch.sourceforge.net/
MapIt!                                           http://www.mapit.de/



More information about the Python-list mailing list