Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #32355

Re: Negative array indicies and slice()

Path csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <andrew3@r3dsolutions.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'argument': 0.04; 'explicitly': 0.04; 'modified': 0.05; 'method,': 0.07; 'override': 0.07; 'received:64.202.165': 0.07; 'wrapper': 0.07; '"a"': 0.09; 'called.': 0.09; 'special,': 0.09; 'subject:()': 0.09; 'index': 0.13; 'dictionary,': 0.16; 'lambda': 0.16; 'notation,': 0.16; 'slice.': 0.16; 'subject:array': 0.16; 'thinking,': 0.16; 'defined': 0.22; 'idea': 0.24; 'pass': 0.25; 'header:User- Agent:1': 0.26; 'start,': 0.27; 'arguments.': 0.29; 'class': 0.29; "i'm": 0.29; 'function': 0.30; 'error': 0.30; 'url:python': 0.32; 'could': 0.32; 'hopefully': 0.33; 'to:addr:python-list': 0.33; 'list': 0.35; 'sequence': 0.35; 'something': 0.35; 'there': 0.35; 'url:org': 0.36; "wasn't": 0.36; 'method': 0.36; 'skip:p 20': 0.36; 'itself': 0.37; 'ok,': 0.37; 'why': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'sure': 0.38; 'to:addr:python.org': 0.39; 'apply': 0.39; 'step': 0.39; 'where': 0.40; 'range': 0.60; 'information': 0.63; 'love': 0.63; 'more': 0.63; 'within': 0.64; 'to,': 0.65; 'header:Reply-To:1': 0.68; 'reply-to:no real name:2**0': 0.72; '*really*': 0.84; 'stop,': 0.84
Date Sun, 28 Oct 2012 19:31:57 -0700
From Andrew Robinson <andrew3@r3dsolutions.com>
User-Agent Mozilla/5.0 (X11; Linux i686; rv:8.0) Gecko/20111126 Thunderbird/8.0
MIME-Version 1.0
To python-list@python.org
Subject Re: Negative array indicies and slice()
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
Reply-To andrew3@r3dsolutions.com
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3002.1351503232.27098.python-list@python.org> (permalink)
Lines 34
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1351503232 news.xs4all.nl 6877 [2001:888:2000:d::a6]:57386
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:32355

Show key headers only | View raw


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,
http://www.python.org/doc//current/c-api/slice

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: ....

--Andrew.


Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Negative array indicies and slice() Andrew Robinson <andrew3@r3dsolutions.com> - 2012-10-28 19:31 -0700

csiph-web