Note: Avoid reading with new line line = line.strip() or print(line,end='')
1 2 3 4 5
with open('test.txt') as f,open('out.txt', 'w') as f_out: for line in f: line = line.strip() print(line)
Ex2: Read a file from text file and write to another file
1 2 3 4 5 6
with open('test.txt') as f,open('out.txt', 'w') as f_out: for line in f: line = line.strip() #print(line) f_out.write('{}\n'.format(line))
ex3 write file
1 2 3 4 5 6
with open ('video_title_url.txt', 'w', encoding='UTF-8') as f_out: for line_index in downloadlink: line = line_index.strip() f_out.write('{}\n'.format(line)) print("end")