+2 votes
in Programming Languages by (71.8k points)
I have an input text file with several records. Some of the records might be empty. How can I skip such records in python? I tried to use len(line), but it didn't work.

1 Answer

+2 votes
by (71.8k points)
selected by
 
Best answer
You can use split() function to check the empty line. For example, see the following code.

with open('badlinks.txt', 'r') as bl:
    for line in bl:
        if line.strip() == '':
            continue
        else:
            id, skey = line.split('||||')
            print id

Related questions


...