[Python-Dev] Re: PEP 326 now online
bob at redivi.com
Tue Jan 6 23:15:13 EST 2004
> > Module attributes make sense; make them attributes of object has
> > the unfortunate side effect that they will be attributes of *all*
> > objects and that doesn't seem a good idea.
> > The math module is only appropriate if this is primarily about float
> > numbers. And see PEP 747 in that case.
> You mean PEP 754, right? Just like creating an arbitrarily large
> integer, floating point infinity is also arbitrary, and may not be big
> I just got a comment from another user suggesting modifying the
> min/max.__cmp__ so that they are the actual minimum and maximum.
> An interesting approach, which makes some sense to me.
[[ I apologize in advance for not carrying along the In-Reply-To and
References headers, I just finally got around to subscribing to this
This was my suggestion. I am for this PEP and am willing to write the
reference implementation for the new min and max builtins if there's
I have, like some others here, used my own One True Large Object. I
think the best reason to have One True Large Object is because you
can't really compare two implementations of the One True Large Object
and expect to get a meaningful result out of it.
For the record, my use case had to do with a giant sorted list of
tuples and the bisect module. The first element of a tuple was a
timestamp, the rest of the tuple isn't worth explaining but I never
wanted to compare against it. The "database" had two primary
operations, inserting records *after* a timestamp, and finding every
record between two timestamps. Let's take a look:
>>> from random import randrange
>>> from pprint import pprint
>>> from bisect import bisect_left, bisect_right
>>> lst = [(randrange(10), randrange(10)) for i in xrange(10)]
>>> bisect_left(lst, (6,))
>>> bisect_right(lst, (6,))
Well, that doesn't look too useful does it? In order for bisect_right
to have a meaningful return value in this case, I need to build an
object such that it compares greater than any (6, *foo).
>>> class MaxObject:
... def __cmp__(self, other):
... return int(not self is other)
>>> maxobject = MaxObject()
>>> bisect_right(lst, (6, maxobject))
[(6, 5), (6, 8), (6, 9)]
In this particular contrived case, sys.maxint would have worked, but
the general case needs One True Large Object. I think One True Large
Object should be in builtins and should be called 'max'. Similarly,
there are probably use cases for One True Small Object, but none that
I've personally ran into. However, since 'min' is already in builtins,
might as well do it for symmetry.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 2357 bytes
Desc: not available
Url : http://mail.python.org/pipermail/python-dev/attachments/20040106/be0f57a5/smime.bin
More information about the Python-Dev