python-kurs-softed/beispiele/readfile3.py

17 lines
375 B
Python

#!/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(data):
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}.")