python-kurs-softed/beispiele/readfile2.py

15 lines
299 B
Python
Raw Normal View History

#!/usr/bin/env python
import sys
filename = sys.argv[1]
with open(filename, "r") as fileobj:
data = fileobj.read()
max_linelength = 0
for line in data.splitlines():
max_linelength = max(max_linelength, len(line))
print(f"The longest line has a length of {max_linelength}.")