with open('nums.txt') as f: total = sum(int(line.strip()) for line in f if line.strip()) print(total)