f = open('/etc/motd', 'r') longest = 0 allLines = f.readlines() f.close() for line in allLines: linelen = len(line.strip()) if linelen > longest: longest = linelen print longest