with open('data.txt', 'r') as f: lines = f.readlines() num_lines = len([l for l in lines if l.strip(' ') != ''])