+2 votes
in Programming Languages by (11k 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

0 votes
by (11k points)
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
...