Top and Bottom Values [PEP: 326]

A

Antoon Pardon

Antoon said:
Antoon Pardon wrote:

What bothers me a bit about the rejection of PEP 326 is that one of the
reasons stated is:

http://mail.python.org/pipermail/python-dev/2004-January/042306.html

- it is easily implemented when you really need it

Well I thought it would simplify some things for me, so I tried an
implementation and then found that some of the things that I would
want to do with it wont work. So the "is easily implemented" bit
seems not to be correct.

IIRC, the PEP proposed the Smallest and Largest singletons with the
sole purpose of being used in comparisons. No numeric behavior was
implied, i.e. Smallest and Largest are not negative and positive
infinity in the math sense of the word.

That is true.
So I guess the "easily implemented" refers to this case alone.

This doesn't follow. Take the example were I got stuck.
lst = range(10)
lst[:Top]

FWIW, this works with 2.5 and the __index__ slot:
... def __index__(self):
... return sys.maxint
...
a=range(5)
a[:Top()] [0, 1, 2, 3, 4]

It is something worth investigating, but I'm not sure it
will suite my purpose. You see I have a table module,
a table is like a list except the base index doesn't need
to be 0. So I could have a table that is indexable from
sys.maxint - 3 to sys.maxint + 7. I'm not sure tbl[:Top]
would do what it is supposed to do in those circumstances.
 
P

Paul Rubin

Antoon Pardon said:
It is something worth investigating, but I'm not sure it
will suite my purpose. You see I have a table module,
a table is like a list except the base index doesn't need
to be 0. So I could have a table that is indexable from
sys.maxint - 3 to sys.maxint + 7. I'm not sure tbl[:Top]
would do what it is supposed to do in those circumstances.

Top = object()

class Table(list):
def __getitem__(self, n):
get = super(Table, self).__getitem__
if n is Top:
return get(-1)
return get(n - self.baseindex)

a=Table(range(9))
a.baseindex = 3
2 8
 
P

Paul Rubin

Paul Rubin said:
sys.maxint - 3 to sys.maxint + 7. I'm not sure tbl[:Top]
would do what it is supposed to do in those circumstances.
Top = object()
class Table(list):
....

Oh wait, I missed the : in your tbl[:Top] example. Yeah, you could
hair up Table to account for slices, I'll leave the exercise to you.
 
A

Antoon Pardon

Paul Rubin said:
sys.maxint - 3 to sys.maxint + 7. I'm not sure tbl[:Top]
would do what it is supposed to do in those circumstances.
Top = object()
class Table(list):
...

Oh wait, I missed the : in your tbl[:Top] example. Yeah, you could
hair up Table to account for slices, I'll leave the exercise to you.

Yes, I could hair up Table, but that is missing the point somewhat.
The idea for provinding extreme values is that you don't have to
hair up the code.

In any case it seems I have my answer. I have some suggestions I can
try out, but writing up once own module for extreme values isn't as
easy as is suggested in the rejection of the PEP and there is probably
very little chance to get the PEP reopened.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top