Answers for "read txt python specify line break character"

2

python read text file next line

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 April-03-2021
1

write lines python with line breaks

fw.write('\n'.join(line_list) + '\n')
Posted by: Guest on July-31-2020

Python Answers by Framework

Browse Popular Code Answers by Language