# Get the number of lonest line
f = open('nihao')
longestLine = max(len(line.strip()) for line in f)
f.close()
print longestLine
# Get the longest line
f = open('nihao')
allLines = [line.strip() for line in f]
f.close()
longest = 0
longLine = ""
for line in allLines:
linelen = len(line)
if linelen > longest:
longest = linelen
longLine = line
print 'Longest line: %s' % longLine
print 'The number of longest line: %s' % longest
Python 获取文件中最长行的长度和最长行
最新推荐文章于 2024-07-16 18:52:34 发布