Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Ganesh Pal Newsgroups: comp.lang.python Subject: list index out of range Error , need to fix it or ignore it Date: Sat, 27 Feb 2016 22:20:10 +0530 Lines: 81 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de 0lcph8i2bI99wlSBfnKSdA+RSrPY17NdywnXhnnJw0iQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'root': 0.04; '"""': 0.05; '__name__': 0.07; 'filename': 0.07; 'main()': 0.07; 'skip:/ 10': 0.07; 'subject:Error': 0.07; 'cmd': 0.09; 'exited': 0.09; 'func': 0.09; 'lines:': 0.09; 'subject:ignore': 0.09; 'python': 0.10; 'exception': 0.13; 'index': 0.13; 'def': 0.13; "'__main__':": 0.16; 'main():': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:need': 0.18; 'try:': 0.18; 'input': 0.18; 'to:name :python-list@python.org': 0.20; 'fix': 0.21; 'machine': 0.21; 'fine,': 0.22; 'ok.': 0.22; 'feb': 0.23; 'example': 0.26; 'subject:list': 0.26; 'command': 0.26; 'linux': 0.26; 'error': 0.27; 'message-id:@mail.gmail.com': 0.27; '2.6': 0.27; "skip:' 10": 0.28; 'fine': 0.28; 'print': 0.30; 'run': 0.33; 'extract': 0.33; 'file': 0.34; 'except': 0.34; 'received:google.com': 0.35; 'false': 0.35; 'machines': 0.35; 'expected': 0.35; 'but': 0.36; 'there': 0.36; 'lines': 0.36; 'received:209.85': 0.36; 'to:addr :python-list': 0.36; 'received:209': 0.38; 'to:addr:python.org': 0.40; 'here': 0.66; 'touch': 0.66; 'wheel': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to; bh=JshLsx8viy0KJuhcUU6j5Iuu4DD8DvOqYPKVoiTsKcI=; b=sWFT95K3AI4mQe7DMi9+BMMp/Jyba8YP2HA25aNEn8P7zlK3i7NFIa5viOQmbXc6cF snPGpRnBxQ8uDOqGY9Q+VCqijDXfaNGrI0n08EDldQZAVZnRH2EsiavmzeNczYpOQ/Mq fE0+SB319spVXmsRsFFnUyM0YtP5USBMs3rO8qe26UAivopmG1ZAH9MFvpKtm/7fi7vi jZpmYvyQpgG3aZ/XBnoiFbFGZF+CDkHk526rrGok8uhRGA1a1FCdOwJlmgcIIuJDCpsC AnUvtU0omxC3eqJleoqoyODXZLfe+SGMK+EKEDuxr9ygrfkLsHa0jpcfjdawbMcbwXMo HulA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to; bh=JshLsx8viy0KJuhcUU6j5Iuu4DD8DvOqYPKVoiTsKcI=; b=Wbz5E5LHyxcfyqlkePEdHiFe6p+0YDi1KY+2UG+OHh01OIULMxOX/w5W8T3GP/mqHY EjPTt7oBGaj91JzNVCbaa4k4Ho23KJYnpzRgGoOqnDNMtBWIlEaN7DcsAvWwoFGo3Qdf b7Yyba9KxWUKFcSATK6KfQKVzTTHZxtYXnsEofrHW5WtMrf8zEqzg0znVayK021FiaCl PvkQ3pvyAFWZnCicKWHFCysmxUsEKvsnDlYxLOQ1yEZ+cFTgn3RMDaPwbZPEY8IIE6kh infaYY7Ux3GLGzeyh+utxorWR3Kp4Gq0wLDFLg4S3/w/xn1rZ8PsYO6evtcuwK6wV+d1 Q4PQ== X-Gm-Message-State: AD7BkJI+NSq4ld8WGKaCapqcnijbbQIo6bG8M2knTelZ/NAWZeBF/emx4AuWuzHJdMHGABWQl6DkiFcwFD4OPg== X-Received: by 10.112.14.102 with SMTP id o6mr2544196lbc.87.1456591810344; Sat, 27 Feb 2016 08:50:10 -0800 (PST) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21rc2 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:103592 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 baddr = '' 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.If the file is present in any one of the machine the program works fine , example if the file is in machine4 it works fine, machine-4# touch /tmp2/2.txt machine-4# python c_4.py run_al_parall 'ls -al /tmp2/2.txt' machine-4: -rw-r--r-- 1 root wheel 0 Feb 27 08:15 /tmp2/2.txt gpal-machine-2 exited with status 1 gpal-machine-5 exited with status 1 gpal-machine-3 exited with status 1 gpal-machine-1 exited with status 1 ['machine-4: -rw-r--r-- 1 root wheel 0 Feb 27 08:15 /tmp2/2.txt', 'gpal-machine-2 exited with status 1', 'gpal-machine-5 exited with status 1', 'gpal-machine-3 exited with status 1', 'gpal-machine-1 exited with status 1'] 2.txt 2. 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 Regards, Ganesh