python - IndexError: list index out of range? -
i have problem, need help of everyone. read rar file (100mb) , process text file (include in rarfile).
import glob import os import unrar2 os import path, access, r_ok os.chdir("e:\\sms") file in glob.glob("*.rar"): # extract test.txt memory entries = unrar2.rarfile(file).read_files('*.txt') test_content = entries[0][1] #print test_content line in test_content.split("\n"): a=line.split(' ') print a[1]
result:
19009057 7030 9119 9119 .... .... bla...bla... ...... 9119 9119 9119 7050 9119 traceback (most recent phone call last): file "e:\laptrinh\android\adt-bundle-windows\eclipse\plugins\org.python.pydev_2.7.1.2012100913\pysrc\pydevd.py", line 1397, in <module> debugger.run(setup['file'], none, none) file "e:\laptrinh\android\adt-bundle-windows\eclipse\plugins\org.python.pydev_2.7.1.2012100913\pysrc\pydevd.py", line 1090, in run pydev_imports.execfile(file, globals, locals) #execute script file "c:\users\the\documents\workspace\unrar\test_unrar.py", line 13, in <module> print a[1] indexerror: list index out of range
please, help me! give thanks you!!!
one of lines (probably last) not in format expect. in inner loop:
a=line.split(' ') if len(a) > 1: print a[1]
python list
No comments:
Post a Comment