Answers for "line for line in lines python"

18

python how to count the lines in a file

# Basic syntax:
count = len(open('/path/to/the/file.ext').readlines())
Posted by: Guest on October-04-2020
0

read a file line-byline in python

filepath = 'Iliad.txt'
with open(filepath) as fp:
   line = fp.readline()
   cnt = 1
   while line:
       print("Line {}: {}".format(cnt, line.strip()))
       line = fp.readline()
       cnt += 1
Posted by: Guest on November-03-2021

Python Answers by Framework

Browse Popular Code Answers by Language