Re: Can't get around "IndexError: list index out of range"

2006-10-10 Thread MonkeeSage
On Oct 10, 1:57 am, Steve Holden <[EMAIL PROTECTED]> wrote: > I think we'll just have to agree to differ in this repsecrt, as I don't > see your suggestions for extending the sequence API as particularly > helpful. No worries. :) On Oct 10, 11:22 am, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > s

Re: Can't get around "IndexError: list index out of range"

2006-10-10 Thread Fredrik Lundh
> *) insert martelli essay here. for example: http://mail.python.org/pipermail/python-list/2003-May/163820.html -- http://mail.python.org/mailman/listinfo/python-list

Re: Can't get around "IndexError: list index out of range"

2006-10-10 Thread Fredrik Lundh
Terry Reedy wrote: > Is there an outer loop being 'break'ed? yes. > This break is swallowed by the for loop, so not exactly equivalent, I > think. the code is supposed to break out of the outer loop when it runs out of lines, so yes, monkeeboy's code is broken in more than one way. > In any

Re: Can't get around "IndexError: list index out of range"

2006-10-10 Thread Fredrik Lundh
MonkeeSage wrote: > In Libs/site.py, lines 302-306: > > try: > for i in range(lineno, lineno + self.MAXLINES): > print self.__lines[i] > except IndexError: > break > > With my proposal, that could be written as: > >

Re: Can't get around "IndexError: list index out of range"

2006-10-10 Thread Terry Reedy
"MonkeeSage" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > But even so, here is a simple use case from the standard library > (python 2.5 release source): > > In Libs/site.py, lines 302-306: > >try: >for i in range(lineno, lineno + self.MAXLINES): >

Re: Can't get around "IndexError: list index out of range"

2006-10-09 Thread Steve Holden
MonkeeSage wrote: > On Oct 9, 2:31 am, Steve Holden <[EMAIL PROTECTED]> wrote: > >>Keep right on guessing. > > > I hope I'm not offending one whom I consider to be much more skilled > and versed than I am, not only in python, but in programming in > general; but I must say: it seems you are bein

Re: Can't get around "IndexError: list index out of range"

2006-10-09 Thread MonkeeSage
On Oct 9, 2:31 am, Steve Holden <[EMAIL PROTECTED]> wrote: > Keep right on guessing. I hope I'm not offending one whom I consider to be much more skilled and versed than I am, not only in python, but in programming in general; but I must say: it seems you are being rather obtuse here. I think I l

Re: Can't get around "IndexError: list index out of range"

2006-10-09 Thread Steve Holden
MonkeeSage wrote: > On Oct 8, 3:05 pm, Steve Holden <[EMAIL PROTECTED]> wrote: > >>No: you are proposing to add features to the sequence interface for >>which there are few demonstrable use cases. > > > If I really wanted to find them, how many instances do you think I > could find [in the stand

Re: Can't get around "IndexError: list index out of range"

2006-10-08 Thread MonkeeSage
On Oct 8, 3:05 pm, Steve Holden <[EMAIL PROTECTED]> wrote: > No: you are proposing to add features to the sequence interface for > which there are few demonstrable use cases. If I really wanted to find them, how many instances do you think I could find [in the standard lib and community-respected

Re: Can't get around "IndexError: list index out of range"

2006-10-08 Thread Fredrik Lundh
MonkeeSage wrote: >> but "let's hypergeneralize and treat sequences and mappings as the same >> thing" proposals are nothing new; a trip to the archives might be help- >> ful. > > Huh? I don't want to treat sequences and mappings as the same thing. > I'm talking about adding two similar convenien

Re: Can't get around "IndexError: list index out of range"

2006-10-08 Thread Steve Holden
MonkeeSage wrote: > On Oct 8, 1:44 pm, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > >>but "let's hypergeneralize and treat sequences and mappings as the same >>thing" proposals are nothing new; a trip to the archives might be help- >>ful. > > > Huh? I don't want to treat sequences and mappings as

Re: Can't get around "IndexError: list index out of range"

2006-10-08 Thread MonkeeSage
On Oct 8, 1:44 pm, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > but "let's hypergeneralize and treat sequences and mappings as the same > thing" proposals are nothing new; a trip to the archives might be help- > ful. Huh? I don't want to treat sequences and mappings as the same thing. I'm talking a

Re: Can't get around "IndexError: list index out of range"

2006-10-08 Thread Fredrik Lundh
MonkeeSage wrote: > With list.has_index() / get(), the following (pretty common I think) > idiom: > > try: > data = some_unknown_seq[2] > except IndexError: > data = None > if data: ... umm. you could at least write: try: data = some_unknown_seq[2] except IndexError:

Re: Can't get around "IndexError: list index out of range"

2006-10-08 Thread MonkeeSage
On Oct 8, 5:57 am, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > No, *less* often. That's the point -- it is fairly common for people to > want dictionary lookup to return a default value, but quite rare for them > to want sequence lookup to return a default value. A sequence with a > default value

Re: Can't get around "IndexError: list index out of range"

2006-10-08 Thread Steven D'Aprano
On Sat, 07 Oct 2006 18:06:47 -0700, MonkeeSage wrote: > On Oct 7, 7:59 pm, Steven D'Aprano > <[EMAIL PROTECTED]> wrote: >> Because they aren't needed often, and when they are, they are easy to >> implement? > > More often and easier to implement than dict.has_key / get? No, *less* often. That's

Re: Can't get around "IndexError: list index out of range"

2006-10-07 Thread MonkeeSage
On Oct 7, 8:06 pm, "MonkeeSage" <[EMAIL PROTECTED]> wrote: > More often and easier to implement than dict.has_key / get? More -> Less -- http://mail.python.org/mailman/listinfo/python-list

Re: Can't get around "IndexError: list index out of range"

2006-10-07 Thread Duncan Smith
MonkeeSage wrote: > > On Oct 7, 7:14 pm, Duncan Smith <[EMAIL PROTECTED]> wrote: > >>No. The above constructs a list of keys and searches the list for the >>key, O(n). "key in somedict" is a lookup, O(1). > > > My point wasn't in regard to implementation details, but in regard to > convenienc

Re: Can't get around "IndexError: list index out of range"

2006-10-07 Thread MonkeeSage
On Oct 7, 7:41 pm, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > Are you just making a philosophical point? In which case I agree: *if* you > make the analogy "a dictionary key is analogous to a sequence index", > *then* the operation of "in" isn't semantically analogous between mappings > and sequ

Re: Can't get around "IndexError: list index out of range"

2006-10-07 Thread Steven D'Aprano
On Sat, 07 Oct 2006 17:25:15 -0700, MonkeeSage wrote: > My point wasn't in regard to implementation details, but in regard to > convenience methods. Obviously the sugary dict methods are tweaked for > the best performance (one would hope!), as would be sugary sequence > methods were they to be add

Re: Can't get around "IndexError: list index out of range"

2006-10-07 Thread Steven D'Aprano
On Sat, 07 Oct 2006 10:26:22 -0700, MonkeeSage wrote: > > > On Oct 7, 3:27 am, Gabriel Genellina <[EMAIL PROTECTED]> wrote: >> The meaning comes from the most common usage. > > I wasn't suggesting that the "in" keyword have a different sematic for > sequence types. I was just saying that regard

Re: Can't get around "IndexError: list index out of range"

2006-10-07 Thread MonkeeSage
On Oct 7, 7:14 pm, Duncan Smith <[EMAIL PROTECTED]> wrote: > No. The above constructs a list of keys and searches the list for the > key, O(n). "key in somedict" is a lookup, O(1). My point wasn't in regard to implementation details, but in regard to convenience methods. Obviously the sugary d

Re: Can't get around "IndexError: list index out of range"

2006-10-07 Thread Duncan Smith
MonkeeSage wrote: > On Oct 7, 12:37 pm, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > >>for what? > > > key in self.keys() > [snip] No. The above constructs a list of keys and searches the list for the key, O(n). "key in somedict" is a lookup, O(1). Duncan -- http://mail.python.org/mailman

Re: Can't get around "IndexError: list index out of range"

2006-10-07 Thread MonkeeSage
On Oct 7, 12:37 pm, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > for what? key in self.keys() And d.get() looks like sugar for: if self.has_key(key): return self[key] else: return default_value Why not have the same sugar for sequence types? E.g., def has_index(self, index):

Re: Can't get around "IndexError: list index out of range"

2006-10-07 Thread Fredrik Lundh
MonkeeSage wrote: > True. But valid dictionary keys are exactly d.keys(). The has_key > method is just sugar. for what? are you sure you're using "sugar" as it is usually used when talking about computer languages? -- http://mail.python.org/mailman/listinfo/python-list

Re: Can't get around "IndexError: list index out of range"

2006-10-07 Thread MonkeeSage
On Oct 7, 3:27 am, Gabriel Genellina <[EMAIL PROTECTED]> wrote: > The meaning comes from the most common usage. I wasn't suggesting that the "in" keyword have a different sematic for sequence types. I was just saying that regarding the question whether there is anything similar to "dict.has_key

Re: Can't get around "IndexError: list index out of range"

2006-10-07 Thread Gabriel Genellina
At Saturday 7/10/2006 02:15, MonkeeSage wrote: On Oct 6, 8:23 pm, Gabriel Genellina <[EMAIL PROTECTED]> wrote: > if 2 in [1,2,3]: print "Use the same (in) operator" > elif 'E' in ('E','r','i','k'): print "Works for any sequence" > elif 'o' in 'hello': print "Even strings" This isn't really anal

Re: Can't get around "IndexError: list index out of range"

2006-10-06 Thread MonkeeSage
On Oct 6, 8:23 pm, Gabriel Genellina <[EMAIL PROTECTED]> wrote: > if 2 in [1,2,3]: print "Use the same (in) operator" > elif 'E' in ('E','r','i','k'): print "Works for any sequence" > elif 'o' in 'hello': print "Even strings" This isn't really analogous is it? For "somedict.has_key(k)" or "k in

Re: Can't get around "IndexError: list index out of range"

2006-10-06 Thread hanumizzle
On 6 Oct 2006 16:57:23 -0700, erikcw <[EMAIL PROTECTED]> wrote: > I ended up using len(sys.argv) > 1 for this particular problem. But I > think slicing is closer to the tool I was looking for. > > I found a.has_key(k) or "k in a" for dictionaries - but haven't found > anything similar for lists.

Re: Can't get around "IndexError: list index out of range"

2006-10-06 Thread Gabriel Genellina
At Friday 6/10/2006 20:57, erikcw wrote: I ended up using len(sys.argv) > 1 for this particular problem. But I think slicing is closer to the tool I was looking for. I found a.has_key(k) or "k in a" for dictionaries - but haven't found anything similar for lists. Does it exist? if 2 in [1,2

Re: Can't get around "IndexError: list index out of range"

2006-10-06 Thread erikcw
I ended up using len(sys.argv) > 1 for this particular problem. But I think slicing is closer to the tool I was looking for. I found a.has_key(k) or "k in a" for dictionaries - but haven't found anything similar for lists. Does it exist? I guess my example from php would technically be a dictio

Re: Can't get around "IndexError: list index out of range"

2006-10-03 Thread Steve Holden
[EMAIL PROTECTED] wrote: > Hi all, > > I'm sorry about the newbie question, but I've been searching all > afternoon and can't find the answer! > > I'm trying to get this bit of code to work without triggering the > IndexError. > > import shutil, os, sys > > if sys.argv[1] != None: > ver = s

Re: Can't get around "IndexError: list index out of range"

2006-10-03 Thread John Machin
Terry Reedy wrote bloated code: > if sys.argv[1:2] != []: if sys.argv[1:2]: :-) -- http://mail.python.org/mailman/listinfo/python-list

Re: Can't get around "IndexError: list index out of range"

2006-10-03 Thread Terry Reedy
"Leif K-Brooks" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > [EMAIL PROTECTED] wrote: >> I'm trying to get this bit of code to work without triggering the >> IndexError. >> >> import shutil, os, sys >> >> if sys.argv[1] != None: >> ver = sys.argv[1] >> else: >> ver = '2.1

Re: Can't get around "IndexError: list index out of range"

2006-10-03 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > I'm trying to get this bit of code to work without triggering the > IndexError. > > import shutil, os, sys > > if sys.argv[1] != None: > ver = sys.argv[1] > else: > ver = '2.14' Something like:: if len(sys.argv) > 1: ver = sys.argv[1] else:

Re: Can't get around "IndexError: list index out of range"

2006-10-03 Thread Leif K-Brooks
[EMAIL PROTECTED] wrote: > I'm trying to get this bit of code to work without triggering the > IndexError. > > import shutil, os, sys > > if sys.argv[1] != None: > ver = sys.argv[1] > else: > ver = '2.14' Catch it: try: ver = sys.argv[1] except IndexError: ver = '2.14' -- htt

Can't get around "IndexError: list index out of range"

2006-10-03 Thread erikwickstrom
Hi all, I'm sorry about the newbie question, but I've been searching all afternoon and can't find the answer! I'm trying to get this bit of code to work without triggering the IndexError. import shutil, os, sys if sys.argv[1] != None: ver = sys.argv[1] else: ver = '2.14' Of course, whe