我在python2.7.9中运行一个代码,因此代码可以正常工作,但是我在python2.7.5中运行的相同代码却给我带来了价值错误。
能帮您解决这个问题吗?
代码:
import os
import sys
table = sys.argv[1] #CALL_KEY
column_nm = sys.argv[2] #ID
file_loc = '/medaff/eureka/RawLayer/AMPIL/'
lkp_file_path ='/medaff/eureka/AMPIL_INCREMENT/'
tgt_file_path ='/medaff/eureka/AMPIL_UNMATCHED/'
def get_col_index(file,col):
header=open(file).readline().strip()
header_list = header.split('|')
return str(header_list.index(col)+1)
src_file_nm = file_loc+table+'/'+table+'.txt'
lkp_file = lkp_file_path+table+'/'+table+'.txt'
trgt_file_nm = tgt_file_path+table+'/'+table+'_Unmatched.txt'
print(lkp_file)
rm_str = 'rm -f '+trgt_file_nm
print(rm_str)
matcher_str = 'awk -F \'|\' \'NR==FNR && NR>1{id[toupper($' + get_col_index(lkp_file,column_nm) + ')]; next} !(toupper(' + get_col_index(src_file_nm,column_nm) + ') in id)\' '+lkp_file+' '+src_file_nm+'|tail -n +2 >> '+trgt_file_nm
os.system(matcher_str)
错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 4, in get_col_index
ValueError: 'ID' is not in list