python-kurs-softed/beispiele/readfile3.py

17 lines
378 B
Python
Raw Permalink Normal View History

#!/usr/bin/env python
import sys
filename = sys.argv[1]
with open(filename, "r") as fileobj:
max_linelength = 0
longest_line = -1
for i, line in enumerate(fileobj):
if len(line) > max_linelength:
max_linelength = len(line)
longest_line = i + 1
print(f"The longest line is line {longest_line} with a length of {max_linelength}.")