Re: Button press event - event handling and picking: IndexError: list index out of range

2020-06-09 Thread Cousin Stanley
Caledonian26 wrote: > However, I keep getting the error: > > IndexError: list index out of range. > > Could anyone give me a helping hand > as to where I am going wrong? > I appended a single arbitrary value for limits since the limits list ha

Re: Button press event - event handling and picking: IndexError: list index out of range

2020-06-07 Thread DL Neil via Python-list
On 8/06/20 10:38 AM, MRAB wrote: On 2020-06-07 23:24, DL Neil via Python-list wrote: On 8/06/20 7:06 AM, Caledonian26 wrote: ... However, I keep getting the error: IndexError: list index out of range. Could anyone give me a helping hand as to where I am going wrong? When things go wrong

Re: Button press event - event handling and picking: IndexError: list index out of range

2020-06-07 Thread MRAB
On 2020-06-07 23:24, DL Neil via Python-list wrote: On 8/06/20 7:06 AM, Caledonian26 wrote: ... However, I keep getting the error: IndexError: list index out of range. Could anyone give me a helping hand as to where I am going wrong? When things go wrong, Python tries to be helpful by

Re: Button press event - event handling and picking: IndexError: list index out of range

2020-06-07 Thread DL Neil via Python-list
On 8/06/20 7:06 AM, Caledonian26 wrote: ... However, I keep getting the error: IndexError: list index out of range. Could anyone give me a helping hand as to where I am going wrong? When things go wrong, Python tries to be helpful by providing a "traceback". Please copy-paste

Button press event - event handling and picking: IndexError: list index out of range

2020-06-07 Thread Caledonian26
larMappable(cmap=cmap, norm=norm) plt.gcf().colorbar(sm) plt.show() 4. Here, a different colour is assigned to each bar in the bar chart depending on the values in the column 'colourofbars'. I then try to plot a legend showing this colour gradient scale. However, I keep getting the error: IndexError: list index out of range. Could anyone give me a helping hand as to where I am going wrong? -- https://mail.python.org/mailman/listinfo/python-list

Re: IndexError: list index out of range

2016-12-13 Thread Elnaz
On Tuesday, December 13, 2016 at 12:45:49 PM UTC+3:30, Peter Otten wrote: > Elnaz wrote: > > > hi > > i am begginer in python. I have written a code and given this error: > > IndexError: list index out of range > > > > In my program, I have h=32 bits input

Re: IndexError: list index out of range

2016-12-13 Thread Peter Otten
Elnaz wrote: > hi > i am begginer in python. I have written a code and given this error: > IndexError: list index out of range > > In my program, I have h=32 bits input. i divide this 32 bits to 4*8 block > and every 8-block is n. so n=0:7;(h=int(n/4)) I want to rotate 0 to 7

IndexError: list index out of range

2016-12-12 Thread Elnaz
hi i am begginer in python. I have written a code and given this error: IndexError: list index out of range In my program, I have h=32 bits input. i divide this 32 bits to 4*8 block and every 8-block is n. so n=0:7;(h=int(n/4)) I want to rotate 0 to 7 bits for 2 bits: 0,1,2,3,4,5,6,7

Re: list index out of range Error , need to fix it or ignore it

2016-02-28 Thread Oscar Benjamin
On 27 February 2016 at 16:50, Ganesh Pal wrote: > Iam on python 2.6 and Linux , I need input on the below program , > here is the spinet of my program It would be much better if you presented a complete program here. Otherwise the missing parts will confuse people. See: http://sscce.org/ > file

Re: list index out of range Error , need to fix it or ignore it

2016-02-28 Thread Steven D'Aprano
On Sun, 28 Feb 2016 03:50 am, Ganesh Pal wrote: > Iam on python 2.6 and Linux , I need input on the below program , > here is the spinet of my program > > > filename='/tmp2/2.txt' > > def check_file(): > """ > Run the command parallel on all the machines , if there is a > file named /

Re: list index out of range Error , need to fix it or ignore it

2016-02-28 Thread Ganesh Pal
>> > what is run(...) > The run (_ is a wrapper it uses suprocess.Popen and returns stdout ,error and extitcod e > not a good idea to have catchall exception how to fix this ? > >> > return False >> > if __name__ == '__main__': >> > main() >> > >> -- >> > copy and paste your tr

Re: list index out of range Error , need to fix it or ignore it

2016-02-27 Thread Joel Goldstick
On Sat, Feb 27, 2016 at 12:01 PM, Ganesh Pal wrote: > changed baddr="" to file ="" in the example program , sorry for the typo > > > filename='/tmp2/2.txt' > > > > def check_file(): > don't use global filename. just pass filename into check_file def check_file(filename): > > """ > > R

Re: list index out of range Error , need to fix it or ignore it

2016-02-27 Thread Ganesh Pal
changed baddr="" to file ="" in the example program , sorry for the typo > filename='/tmp2/2.txt' > > def check_file(): > """ > Run the command parallel on all the machines , if there is a > file named /tmp/file2.txt extract file2.txt > > """ > global filename > file = '' >

list index out of range Error , need to fix it or ignore it

2016-02-27 Thread Ganesh Pal
Iam on python 2.6 and Linux , I need input on the below program , here is the spinet of my program filename='/tmp2/2.txt' def check_file(): """ Run the command parallel on all the machines , if there is a file named /tmp/file2.txt extract file2.txt """ global filename bad

Re: indexerror: list index out of range??

2013-07-01 Thread Steven D'Aprano
On Mon, 01 Jul 2013 09:45:52 +0100, Robert Kern wrote: > On 2013-06-29 16:52, Joshua Landau wrote: >> On 29 June 2013 15:30, Mark Lawrence wrote: >>> >>> On 29/06/2013 14:44, Dave Angel wrote: Since you're using the arrogant and buggy GoogleGroups, this http://wiki.python.org/moin/

Re: indexerror: list index out of range??

2013-07-01 Thread Robert Kern
On 2013-06-29 16:52, Joshua Landau wrote: On 29 June 2013 15:30, Mark Lawrence wrote: On 29/06/2013 14:44, Dave Angel wrote: Since you're using the arrogant and buggy GoogleGroups, this http://wiki.python.org/moin/GoogleGroupsPython. Please don't make comments like this, you'll upset the P

Re: indexerror: list index out of range??

2013-07-01 Thread Joshua Landau
On 29 June 2013 15:30, Mark Lawrence wrote: > > On 29/06/2013 14:44, Dave Angel wrote: >> >> Since you're using the arrogant and buggy GoogleGroups, this >> http://wiki.python.org/moin/GoogleGroupsPython. >> > Please don't make comments like this, you'll upset the Python Mailing List > Police. *d

Re: indexerror: list index out of range??

2013-06-29 Thread Mark Lawrence
On 29/06/2013 14:44, Dave Angel wrote: On 06/28/2013 11:35 PM, Titiksha wrote: Since you're using the arrogant and buggy GoogleGroups, this http://wiki.python.org/moin/GoogleGroupsPython. Please don't make comments like this, you'll upset the Python Mailing List Police. -- "Steve is going

Re: indexerror: list index out of range??

2013-06-29 Thread Dave Angel
On 06/28/2013 11:35 PM, Titiksha wrote: On Friday, June 28, 2013 8:20:28 PM UTC-5, Titiksha wrote: m=['631138', '601034', '2834', '2908', '64808'] ['LAKEFLD 3227,631138\n', 'NOBLES 3013,601034\n'] Since you're using the arrogant and buggy GoogleGroups, this

Re: indexerror: list index out of range??

2013-06-28 Thread Titiksha
On Friday, June 28, 2013 8:20:28 PM UTC-5, Titiksha wrote: > Hi, > > I am working on the following code but am getting the error: list index out > of range. I surfed through the group but somehow I am not able to fix my > error.Please guide.Structure is given below: >

Re: indexerror: list index out of range??

2013-06-28 Thread Dave Angel
On 06/28/2013 09:20 PM, Titiksha Joshi wrote: Hi, I am working on the following code but am getting the error: list index out of range. I surfed through the group but somehow I am not able to fix my error.Please guide.Structure is given below: m is a list of 5 elements. I have to match

Re: indexerror: list index out of range??

2013-06-28 Thread Chris Angelico
On Sat, Jun 29, 2013 at 11:20 AM, Titiksha Joshi wrote: > Hi, > I am working on the following code but am getting the error: list index out > of range. I surfed through the group but somehow I am not able to fix my > error.Please guide.Structure is given below: > m is a list o

indexerror: list index out of range??

2013-06-28 Thread Titiksha Joshi
Hi, I am working on the following code but am getting the error: list index out of range. I surfed through the group but somehow I am not able to fix my error.Please guide.Structure is given below: m is a list of 5 elements. I have to match elements of m from fields in file ALL_BUSES_FINAL.cvs

Re: List index out of range, but list has enough elements

2010-11-09 Thread Stefan Behnel
. Here's my code: csvfile = csv.reader(datastr.split('\n'), delimiter=';') r = '' for i in csvfile: for j in i: print j print i[0] the "print j" statement works, but "

Re: List index out of range, but list has enough elements

2010-11-09 Thread Costin Gamenț
#x27; >> >>        for i in csvfile: >> >>                for j in i: >> >>                        print j >> >>                print i[0] >> >> >> >> the "print j" statement works, but "print i[0]" re

Re: List index out of range, but list has enough elements

2010-11-09 Thread Nitin Pawar
ncountered an odd > >> problem. Here's my code: > >> > >>csvfile = csv.reader(datastr.split('\n'), delimiter=';') > >>r = '' > >>for i in csvfile: > >>for j in i: > >>

Re: List index out of range, but list has enough elements

2010-11-09 Thread Costin Gamenț
>>                for j in i: >>                        print j >>                print i[0] >> >> the "print j" statement works, but "print i[0]" returns "IndexError: >> list index out of range". Am I missing something? > &

Re: List index out of range, but list has enough elements

2010-11-09 Thread Peter Otten
for j in i: > print j > print i[0] > > the "print j" statement works, but "print i[0]" returns "IndexError: > list index out of range". Am I missing something? Change print i[0] to print i You'

Re: List index out of range, but list has enough elements

2010-11-09 Thread Stefan Behnel
i: print j print i[0] the "print j" statement works, but "print i[0]" returns "IndexError: list index out of range". Am I missing something? Are you sure the output you get from the "print j" is from the same loop ite

List index out of range, but list has enough elements

2010-11-09 Thread Costin Gamenț
print i[0] the "print j" statement works, but "print i[0]" returns "IndexError: list index out of range". Am I missing something? -- http://mail.python.org/mailman/listinfo/python-list

Re: inspect.stack() or inspect.currentframe() gives "list index out of range error"

2010-09-25 Thread Terry Reedy
10:50:38+0300 [-] File "/usr/lib/python2.6/inspect.py", line 568, in findsource 2010-09-25 10:50:38+0300 [-] if pat.match(lines[lnum]): break 2010-09-25 10:50:38+0300 [-] IndexError: list index out of range It is hard to reproduce the error with a script. I will work and send if I succ

Re: inspect.stack() or inspect.currentframe() gives "list index out of range error"

2010-09-25 Thread Wolfgang Rohdewald
On Samstag 25 September 2010, Steven D'Aprano wrote: > My guess is that you've copied the .pyc file onto the server, > BUT there is also an older version of the .py file there as > well. Because the modification date is older than that of the > .pyc file, Python executes the compiled code from the

Re: inspect.stack() or inspect.currentframe() gives "list index out of range error"

2010-09-25 Thread Steven D'Aprano
10:50:38+0300 [-] lines, lnum = findsource(frame) > 2010-09-25 10:50:38+0300 [-] File "/usr/lib/python2.6/inspect.py", > line 568, in findsource > 2010-09-25 10:50:38+0300 [-] if pat.match(lines[lnum]): break > 2010-09-25 10:50:38+0300 [-] IndexError: list index out of

Re: inspect.stack() or inspect.currentframe() gives "list index out of range error"

2010-09-25 Thread deluxstar
e code works on local development environment both on linux > > and windows. When checked in to production environment, > > inspect.currentframe() or inspect.stack() function gives "List index > > out of range error". > > > When I googled, I found only one clue o

Re: inspect.stack() or inspect.currentframe() gives "list index out of range error"

2010-09-24 Thread Peter Otten
ect.currentframe() or inspect.stack() function gives "List index > out of range error". > > When I googled, I found only one clue of copying pyc files: > http://forum.webfaction.com/viewtopic.php?pid=16808 > > Why inspect modules gives this error? OR Is there another wa

inspect.stack() or inspect.currentframe() gives "list index out of range error"

2010-09-24 Thread deluxstar
= inspect.getouterframes(curframe, 2) calframe[1][0].f_locals['variable'] This sample code works on local development environment both on linux and windows. When checked in to production environment, inspect.currentframe() or inspect.stack() function gives "List index out of range error". Whe

Re: list index out of range

2008-05-13 Thread Mike Kent
On May 13, 2:39 pm, Georgy Panterov <[EMAIL PROTECTED]> wrote: > > def deal_hand(deck): > HAND=[] > for _ in range(2): > i=random.randint(0,len(deck)) #produces a random card from the deck ^ Here i can be from 0 thru (the number of cards in the deck). > HAND.appen

Re: list index out of range

2008-05-13 Thread inhahe
then it gives an error of "list index out of range." The strange thing is that it will sometimes run for 10 iterations sometimes for only a few and sometimes won't run at all (seemingly arbitrary). Here is some of the code: for _ in range(100): handA=deal_hand(DECK) #deals 2 &#x

list index out of range

2008-05-13 Thread Georgy Panterov
I am a relatively new python user. I am writing an economic simulation of a card-game. The simulation runs fine for a few iteration but then it gives an error of "list index out of range." The strange thing is that it will sometimes run for 10 iterations sometimes for only a few and

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
ching 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

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

2006-10-03 Thread Steve Holden
os, sys > > if sys.argv[1] != None: > ver = sys.argv[1] > else: > ver = '2.14' > > Of course, whenever I run it, I get list index out of range. > > I'm coming from the php world where I can do: > if $_GET['var'] != Null { > $ver

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
= '2.14' Of course, whenever I run it, I get list index out of range. I'm coming from the php world where I can do: if $_GET['var'] != Null { $ver = $_GET['var']; } else { $ver = '2.14'; } Can anyone tell me how to make this work in python? Thanks! Erik -- http://mail.python.org/mailman/listinfo/python-list

Re: "list index out of range" error

2006-09-20 Thread Tuomas
sam wrote: I gues: no_lines=len(list_initial) > for j in range(0, no_lines): range returns 0, 1, 2, ..., no_lines-1 > > k = 0 > while k < no_lines: > sorted_check = 0 > if list_initial[k] < list_initial[k+1]: When j gets its last value (no_lines-1) k has the same va

Re: "list index out of range" error

2006-09-20 Thread sam
gabriel, > Now that your main problem is gone, just a few comments: > - python lists know their length, so you don't need explicit no_lines > and no_lines_2 > - list_initial.remove(temp_str) is fairly slow - it has to *scan* the > list to locate temp_str. Just keep its index instead, and use del >

Re: "list index out of range" error

2006-09-20 Thread Gabriel Genellina
At Wednesday 20/9/2006 19:39, sam wrote: thanks again for your help. that sorted out something that had really been bugging me. Now that your main problem is gone, just a few comments: - python lists know their length, so you don't need explicit no_lines and no_lines_2 - list_initial.remove(t

Re: "list index out of range" error

2006-09-20 Thread Ben Finney
"sam" <[EMAIL PROTECTED]> writes: > hey everybody, this is my first time posting here. i'm pretty new to > python and programming in general (as you'll soon work out for > yourselves...) On behalf of the entire Python community, *thank you* for putting this disclaimer only in the body of your mes

Re: "list index out of range" error

2006-09-20 Thread sam
for what it's worth. and it is approx. five times quicker than the bubblesort i wrote to begin with on a 286-word highly unordered list, so i wasn't wasting my time after all... __ import time file_input = open('wordlist.txt', 'r

Re: "list index out of range" error

2006-09-20 Thread sam
yes, yes, of course, thank you. not sure what i thought i was doing there. i'll see if i can get it running now... -- http://mail.python.org/mailman/listinfo/python-list

Re: "list index out of range" error

2006-09-20 Thread Marc 'BlackJack' Rintsch
; list_initial[k+1]: > temp_str = list_initial[k+1] > sorted_check = 1 > k += 1 > > list_initial.remove(temp_str) > list_final.append(temp_str) > no_lines -= 1 > > if sorted_check == 0: > break > > problem

Re: "list index out of range" error

2006-09-20 Thread sam
actually, that little bit of code i wrote is obscenely wrong anyway, so please don't bother analyzing the flow. any insight into the "list index out of range" error would still be welcome, though. -- http://mail.python.org/mailman/listinfo/python-list

"list index out of range" error

2006-09-20 Thread sam
itial[k] elif list_initial[k] > list_initial[k+1]: temp_str = list_initial[k+1] sorted_check = 1 k += 1 list_initial.remove(temp_str) list_final.append(temp_str) no_lines -= 1 if sorted_check == 0: break problem is, i keep gett