python - IndexError: list index out of range, but each string can be printed out -
i writing script pool lines filea when first 2 columns same fileb. filea txt file 3 column separated tab, , fileb txt file 2 column separated tab. keeps showing error following: "site=a[0]+’\t’+a[1] indexerror: list index out of range" can print a[0], a[1], a[2] , site.
here code:
fileb=open('atog_mock.txt').readlines() filea=open('depth_ice.txt').readlines() outfile=open('atog_depth_ice.txt','w') dict1={} line in filea: a=line.strip().split('\t') site = a[0]+' '+a[1] if site not in dict1: dict1[site]=a[2] line in fileb: b=line.strip().split('\t') site=b[0]+' '+b[1] if site in dict1: outfile.write(b[0]+'\t'+b[1]+'\t'+dict1[site]+'\n') outfile.close()
i appreciate help!
we can't give definitive answer because don't have access data files, can debug wrapping problematic line in try/except
block:
try: site = a[0]+' '+a[1] except indexerror: print("error: is", a) raise
most there's empty line somewhere, last line.
Comments
Post a Comment