ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> cpp-sig
cpp-sig
[C++-sig] Re: vector_indexing_suite too defensive ...
by Raoul Gough other posts by this author
Sep 30 2003 4:06AM messages near this date
[C++-sig] Re: (no subject) | [C++-sig] On wrapping vector >
"Joel de Guzman" <djowel@[...].uk>  writes:

>  Raoul Gough <RaoulGough@[...].uk> wrote:
> > "Joel de Guzman" <djowel@[...].uk> writes:
> > 
> >> Mike Thompson <mike.thompson@[...].au> wrote:
> > [snip]
> >>> The IndexError arises because vector_indexing_suite defends against
> >>> an slice index being too big, rather than the python list approach
> >>> which regards a slice index > len(L) as equal to len(L).  So, the
> >>> line of padOrChop() which says:
> >>> 
> >>>     lst[size:] = [padValue] * diff
> >>> 
> >>> causes an exception when size > len(lst).
> >>> 
> >>> Should vector_indexing_suite be altered to give behaviour more like
> >>> that of lists in this regard?
> >> 
> >> It should. I think you uncovered a vector_indexing_suite bug. I'll
> >> correct this as soon as I can.
> > 
> > Hi Joel,
> > 
> > You might find the PySlice_GetIndices function useful - it take a
> > Python slice object and a container length and returns normalized
> > start and stop values (even handling negative indices, IIRC). At a
> > guess, this is probably how the Python list works internally too.
> 
>  I *was* using PySlice_GetIndices. The problem was (if I'm not mistaken),
>  is that it does not handle non-integer inteces. Correct me if I'm wrong.
>  For example, I have a case where the indexes are dates that I must convert
>  to a valid index.

Well, it only works for slices, which (AFAIK) rules out non-integer
values anyway. I'm confused now about what the original problem was,
because I think using PySlice_GetIndices would already rule out any
problems with lst[99999:] and so on. Problems with lst[99999]
(i.e. not a slice) are a different matter, and even Python lists barf
on indexes out of range here.

-- 
Raoul Gough.
(setq dabbrev-case-fold-search nil)


_______________________________________________
C++-sig mailing list
C++-sig@[...].org
http://mail.python.org/mailman/listinfo/c++-sig

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved