Answers for "Write a Python program to read a file line by line and store it into a list."

1

Write a Python program to read a file line by line and store it into a list.

def conftolist(fname,mode='r+'):
	with open(fname) as f:
		lines = [line.strip() for line in f]
		print(lines)

conftolist('file1.txt')
############

with open('file1.txt','r+') as f:
	# li = list(f)
	# print(li)
	ls=[]
	for l in f:
		ls.append(l.strip())
	print(ls)
Posted by: Guest on November-27-2020

Code answers related to "Write a Python program to read a file line by line and store it into a list."

Python Answers by Framework

Browse Popular Code Answers by Language