Answers for "python recall a line from a text file"

1

python recall a line from a text file

# Read text file line by line
filepath = 'text_file.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 April-30-2021

Code answers related to "python recall a line from a text file"

Python Answers by Framework

Browse Popular Code Answers by Language