t_char = 0
try:
with open(file_name) as f:
line = f.readline()
t_char += len(line)
while line:
count += 1
line = f.readline()
t_char += len(line)
except FileNotFoundError as e:
print(e)
After Change
// Source: https://stackoverflow.com/a/1019572
count = (sum(1 for line in f))
f.seek(0)
t_char = (sum([len(line) for line in f]))
except FileNotFoundError as e:
print(e)
sys.exit(1)