with open(nsfile, 'w') as f: found = False for line in lines: found = True