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


Groups > comp.lang.python > #103595

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

From Joel Goldstick <joel.goldstick@gmail.com>
Newsgroups comp.lang.python
Subject Re: list index out of range Error , need to fix it or ignore it
Date 2016-02-27 12:21 -0500
Message-ID <mailman.184.1456593680.20994.python-list@python.org> (permalink)
References <CACT3xuU5L9+EbJcw+L7vySKnYO83MQQ3M4zkMLz2G85dWrBT=g@mail.gmail.com> <CACT3xuWKjiiLWRW1v+e+ySwqM7g-CiZKRD3dy2hhK4XQTzaRHA@mail.gmail.com>

Show all headers | View raw


On Sat, Feb 27, 2016 at 12:01 PM, Ganesh Pal <ganesh1pal@gmail.com> 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):

> >     """
> >      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)
>
what is run(...)

> >     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:
>
not a good idea to have catchall exception

> >             return False
> > if __name__ == '__main__':
> >       main()
> >
> --
>
copy and paste your traceback

> https://mail.python.org/mailman/listinfo/python-list
>



-- 
Joel Goldstick
http://joelgoldstick.com/ <http://joelgoldstick.com/stats/birthdays>
http://cc-baseballstats.info/

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 Joel Goldstick <joel.goldstick@gmail.com> - 2016-02-27 12:21 -0500

csiph-web