Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #32559
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <ethan@stoneleaf.us> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; '(at': 0.03; 'syntax': 0.03; 'elif': 0.04; '*not*': 0.07; 'indices': 0.07; 'method,': 0.07; 'missed': 0.09; 'python': 0.09; '%r"': 0.09; 'calculates': 0.09; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'integers': 0.09; 'loop.': 0.09; 'message-id:@stoneleaf.us': 0.09; 'none.': 0.09; 'notation': 0.09; 'part,': 0.09; 'pep': 0.09; 'received:184.172': 0.09; 'received:gator410.hostgator.com': 0.09; 'slices': 0.09; 'subject:()': 0.09; '~ethan~': 0.09; 'index': 0.13; '(but': 0.15; '(start,': 0.16; '(str,': 0.16; '*only*': 0.16; 'both)': 0.16; 'index;': 0.16; 'least,': 0.16; 'long)):': 0.16; 'numpy': 0.16; 'oct': 0.16; 'offsets': 0.16; 'subclasses,': 0.16; 'subject:array': 0.16; 'syntax.': 0.16; 'thread.': 0.16; 'wed,': 0.16; 'wrote:': 0.17; 'certainly': 0.17; 'implementing': 0.17; 'integer': 0.17; '>>>': 0.18; 'memory': 0.18; '(or': 0.18; '31,': 0.22; 'explicit': 0.22; 'noted': 0.22; 'permitted': 0.22; "i'd": 0.22; 'example': 0.23; '(this': 0.24; 'long,': 0.24; 'raise': 0.24; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'looks': 0.26; 'values': 0.26; 'am,': 0.27; 'andrew': 0.27; 'start,': 0.27; "doesn't": 0.28; 'represent': 0.28; 'strings,': 0.29; 'case,': 0.29; 'convert': 0.29; 'objects': 0.29; "i'm": 0.29; "we're": 0.30; 'notes': 0.30; 'lists': 0.31; 'code': 0.31; '(and': 0.32; 'could': 0.32; 'int': 0.33; 'like:': 0.33; 'to:addr :python-list': 0.33; 'skip:d 20': 0.34; "can't": 0.34; 'skip:b 20': 0.34; 'updated': 0.34; 'sequence': 0.35; 'so,': 0.35; 'doing': 0.35; 'pm,': 0.35; 'something': 0.35; 'there': 0.35; 'but': 0.36; 'method': 0.36; 'anything': 0.36; 'test': 0.36; 'does': 0.37; 'uses': 0.37; 'why': 0.37; 'item': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'things': 0.38; 'nothing': 0.38; 'to:addr:python.org': 0.39; 'step': 0.39; 'header:Received:5': 0.40; 'lost': 0.60; 'most': 0.61; "you've": 0.61; 'mentioned': 0.63; 'note:': 0.64; 'received:69.56': 0.65; 'talking': 0.66; 'special': 0.73; 'gotten': 0.75; '(yes,': 0.84; 'fields,': 0.84; 'forward,': 0.84; 'moves': 0.84; 'stop,': 0.84; 'ethan': 0.91 |
| Date | Thu, 01 Nov 2012 07:12:15 -0700 |
| From | Ethan Furman <ethan@stoneleaf.us> |
| User-Agent | Thunderbird 1.5.0.10 (Windows/20070221) |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: Negative array indicies and slice() |
| References | <509053F2.6020900@r3dsolutions.com> <CALwzidnQ2bUdMp8c0xNomabcLHZBBtr_DYSSzvhz3jqeYNkWkQ@mail.gmail.com> <50912ADC.2020401@r3dsolutions.com> <CALwzid=_1TCQC5JryemVfVpBLWq=qZwy4hRjCPA5ha0vSm3=VA@mail.gmail.com> <50918716.3080305@r3dsolutions.com> |
| In-Reply-To | <50918716.3080305@r3dsolutions.com> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-AntiAbuse | This header was added to track abuse, please include it with any abuse report |
| X-AntiAbuse | Primary Hostname - gator410.hostgator.com |
| X-AntiAbuse | Original Domain - python.org |
| X-AntiAbuse | Originator/Caller UID/GID - [47 12] / [47 12] |
| X-AntiAbuse | Sender Address Domain - stoneleaf.us |
| X-BWhitelist | no |
| X-Source | |
| X-Source-Args | |
| X-Source-Dir | |
| X-Source-Sender | ([192.168.11.101]) [173.12.184.238]:49614 |
| X-Source-Auth | ethan+stoneleaf.us |
| X-Email-Count | 1 |
| X-Source-Cap | dG9idWs7dG9idWs7Z2F0b3I0MTAuaG9zdGdhdG9yLmNvbQ== |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| 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.3149.1351779671.27098.python-list@python.org> (permalink) |
| Lines | 83 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1351779671 news.xs4all.nl 6860 [2001:888:2000:d::a6]:53871 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:32559 |
Show key headers only | View raw
Andrew Robinson wrote:
> On 10/31/2012 02:20 PM, Ian Kelly wrote:
>> On Wed, Oct 31, 2012 at 7:42 AM, Andrew Robinson wrote:
>>> Then; I'd note: The non-goofy purpose of slice is to hold three
>>> data values; They are either numbers or None. These *normally*
>>> encountered values can't create a memory loop.
>>> So, FOR AS LONG, as the object representing slice does not contain
>>> an explicit GC pair; I move that we mandate (yes, in the current
>>> python implementation, even as a *fix*) that its named members may
>>> not be assigned any objects other than None or numbers....
>>>
>>> eg: Lists would be forbidden....
>>>
>>> Since functions, and subclasses, can be test evaluated by int(
>>> the_thing_to_try ) and *[] can too,
>>> generality need not be lost for generating nothing or numbers.
>>
>>
>> PEP 357 requires that anything implementing the __index__ special
>> method be allowed for slicing sequences (and also that __index__ be
>> used for the conversion). For the most part, that includes ints and
>> numpy integer types, but other code could be doing esoteric things
>> with it.
>
> I missed something... (but then that's why we're still talking about it...)
>
> Reading the PEP, it notes that *only* integers (or longs) are permitted
> in slice syntax.
Keep in mind that PEPs represent Python /at that time/ -- as Python
moves forward, PEPs are not updated (this has gotten me a couple times).
>> The change would be backward-incompatible in any case, since there is
>> certainly code out there that uses non-numeric slices -- one example
>> has already been given in this thread.
>
> Hmmm.....
>
> Now, I'm thinking -- The purpose of index(), specifically, is to notify
> when something which is not an integer may be used as an index; You've
> helpfully noted that index() also *converts* those objects into numbers.
>
> Ethan Fullman mentioned that he used the names of fields, "instead of
> having to remember the _offsets_"; Which means that his values _do
> convert_ to offset numbers
Furman, actually. :)
And my values do *not* convert to indices (at least, not automatically).
My __getitem__ code looks like:
elif isinstance(item, slice):
sequence = []
if isinstance(item.start, (str, unicode)) \
or isinstance(item.stop, (str, unicode)):
field_names = dbf.field_names(self)
start, stop, step = item.start, item.stop, item.step
if start not in field_names or stop not in field_names:
raise MissingFieldError(
"Either %r or %r (or both) are not valid field names"
% (start, stop))
if step is not None and not isinstance(step, (int, long)):
raise DbfError(
"step value must be an int or long, not %r"
% type(step))
start = field_names.index(start)
stop = field_names.index(stop) + 1
item = slice(start, stop, step)
for index in self._meta.fields[item]:
sequence.append(self[index])
return sequence
In other words, the slice contains the strings, and my code calculates
the offsets -- Python doesn't do it for me.
> His example was actually given in slice syntax notation [::].
> Hence, his objects must have an index() method, correct?.
Nope.
~Ethan~
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Negative array indicies and slice() Ethan Furman <ethan@stoneleaf.us> - 2012-11-01 07:12 -0700
csiph-web