Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #103616

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

From Ganesh Pal <ganesh1pal@gmail.com>
Newsgroups comp.lang.python
Subject Re: list index out of range Error , need to fix it or ignore it
Date 2016-02-28 14:00 +0530
Message-ID <mailman.1.1456648634.9760.python-list@python.org> (permalink)
References <CACT3xuU5L9+EbJcw+L7vySKnYO83MQQ3M4zkMLz2G85dWrBT=g@mail.gmail.com> <CACT3xuWKjiiLWRW1v+e+ySwqM7g-CiZKRD3dy2hhK4XQTzaRHA@mail.gmail.com> <CAPM-O+wMX2ibRvy8yWAGR+EMxDcstF8mLTkptWOKrVb9_ys09Q@mail.gmail.com>

Show all headers | View raw


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

I get  " ERROR:root:list index out of range" error  if the file  is
not found in any of the machine , I dont have a trackback back


def check_file():
    """
 333333333333333333333333333333333333333333333333333333333333333333333333333333333333
   Run the command parallel on all the machines , if there is a
file named /tmp/file2.txt  extract file2.txt

    """
    global filename
    file = ''
    cmd = ("run_al_paral 'ls -al %s'" % (filename))
    print(cmd)
    stdout, stderr, exitcode = run(cmd)
    print(stdout)
    lines = stdout.strip().split('\n')
    print(lines)
    for line in lines:
        if 'exited' in lines:
            continue

        file = lines[0].split()[9][6:]
        break
    print file
    return file

def main():
    functions = [check_file]
    for func in functions:
        try:
            func()
        except Exception as e:
            return False
if __name__ == '__main__':
      main()














1. But if the file is not present we get index out of range error , do
we need to fix this or its expected ? or its ok.

machine-4# python c_4.py
isi_for_array 'ls -al /tmp2/2.txt'
machine-2 exited with status 1
machine-1 exited with status 1
machine-4 exited with status 1
machine-5 exited with status 1
machine-3 exited with status 1

['machine-2 exited with status 1', 'machine-1 exited with status 1',
'machine-4 exited with status 1', 'machine-5 exited with status 1',
'machine-3 exited with status 1']
ERROR:root:list index out of range

3. Any other tips to improve the program

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: list index out of range Error , need to fix it or ignore it Ganesh Pal <ganesh1pal@gmail.com> - 2016-02-28 14:00 +0530

csiph-web