Get the longest line : Loop through : File PYTHON TUTORIALS


PYTHON TUTORIALS » File » Loop through »

 

Get the longest line


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



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo File
» Loop through