简体   繁体   中英

Python only returning first line of list

When attempting to use this script in conjunction with cat command, I am only getting the first entry, rather than all of them. here is the script:

for line in sys.stdin:
    line       = line.strip() #strip out carriage return
    key_value  = line.split(",")   #split line, into key and value, returns a list
    key_in     = key_value[0]
    value_in   = key_value[1]

#print key_in
if(value_in.isdigit()==True):
    print('%s\t%s' % (key_in, value_in)) 
elif(value_in == 'ABC'):
    print('%s\t%s' % (key_in, value_in))

I am then running cat command on the target files and the script. Thoughts?

Your indentation looks incorrect. Perhaps this is what you're looking for?

for line in sys.stdin:
    line       = line.strip() #strip out carriage return
    key_value  = line.split(",")   #split line, into key and value, returns a list
    key_in     = key_value[0]
    value_in   = key_value[1]

    #print key_in
    if(value_in.isdigit()==True):
        print('%s\t%s' % (key_in, value_in)) 
    elif(value_in == 'ABC'):
        print('%s\t%s' % (key_in, value_in))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM