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 = '' >

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

2010-11-09 Thread Stefan Behnel
[rearranged the responses in the right order] Costin Gamenț, 09.11.2010 11:44: On Tue, Nov 9, 2010 at 3:21 PM, Costin Gamenț wrote: On Tue, Nov 9, 2010 at 11:33 AM, Stefan Behnel wrote: Costin Gamenț, 09.11.2010 10:24: Hi, I am trying to read a string as csv, but I encountered an odd problem.

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

2010-11-09 Thread Costin Gamenț
Thank you all for your interest in my problem. As Peter pointed out, there was one row with zero elements in it and that's where my problem was (of course it was the very last row, hence my confidence I have "good" data). Have a nice one, Costin On Tue, Nov 9, 2010 at 12:02 PM, Nitin Pawar wrote

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

2010-11-09 Thread Nitin Pawar
You may want to try a spilt if you are getting 8 different elements then it will give you a list of those elements On Tue, Nov 9, 2010 at 3:21 PM, Costin Gamenț wrote: > Thank you for your timely response. Yes, I am sure "i" and "j" are > from the same iteration. I should point out that "i" actua

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

2010-11-09 Thread Costin Gamenț
Thank you for your timely response. Yes, I am sure "i" and "j" are from the same iteration. I should point out that "i" actually has 8 elements and that str(i) gives a nice printout. On Tue, Nov 9, 2010 at 11:33 AM, Stefan Behnel wrote: > Costin Gamenț, 09.11.2010 10:24: >> >> Hi, I am trying to

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

2010-11-09 Thread Peter Otten
Costin Gamenț wrote: > Hi, I am trying to read a string as csv, but I encountered an odd > problem. Here's my code: > > csvfile = csv.reader(datastr.split('\n'), delimiter=';') > r = '' > for i in csvfile: > for j in i: > print j >

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

2010-11-09 Thread Stefan Behnel
Costin Gamenț, 09.11.2010 10:24: Hi, I am trying to read a string as csv, but I encountered an odd problem. Here's my code: csvfile = csv.reader(datastr.split('\n'), delimiter=';') r = '' for i in csvfile: for j in i: print j

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
random.randint(x,y) returns a random integer between _and including_ x and y, so randint(0, len(deck)) might return len(deck) and since python's indices start at 0, the maximum index is len(deck)-1. rather than using randint(0,len(deck)-1) you could just do card = random.choice(deck) HAND.append

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
In <[EMAIL PROTECTED]>, sam wrote: > i'm trying to code a version of a selection sort and the heart of the > code is as follows (no_lines is simply the number of items to be > sorted, read out of an input file): > > for j in range(0, no_lines): > > k = 0 > while k < no_lines: > s

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