Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Negative array indicies and slice()

Thread Tools

Re: Negative array indicies and slice()

Andrew Robinson
Posts: n/a
Ok, hopefully this is better. I love my own e-mail editor...

I can see that the slice() function can pass in arbitrary arguments.
I'm not sure for lists, which is what the range is applied to, why an
argument like "a" would be part of a slice.
I *really* don't see what the advantage of a slice class is over a mere
list in the order of start, stop, step eg: [ 1,4,9 ]

In a dictionary, where "a" could be a key -- I wasn't aware that there
was a defined order that the idea of slice could apply to.

When I look at the documentation,

The only thing that slice has which is special, is that the the length
of the sequence can be given -- and the start and stop index are either
trimmed or an error (exception???) is thrown.

Where is the information on the more general case of slice()? :-\

I am thinking, can one use the 'super' type of access, to override --
within the list object itself -- the __getitem__ method, and after
pre-processing -- call the shadowed method with the modified
parameters? That would allow me to use the normal a[-4:6] notation,
without having to write a wrapper class that must be explicitly called.

I'm thinking something like,

PyListObject.__getitem__= lambda self, slice: ....


Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Negative array indicies and slice() Python 72 11-02-2012 01:08 AM
Re: Negative array indicies and slice() Ian Kelly Python 0 10-31-2012 07:43 AM
Re: Negative array indicies and slice() Dennis Lee Bieber Python 0 10-31-2012 03:36 AM
Re: Negative array indicies and slice() Ethan Furman Python 0 10-30-2012 09:21 PM
Re: Negative array indicies and slice() Mark Lawrence Python 0 10-29-2012 10:10 AM