How to read a txt and store its data in a list?

Viewed 20
pathfile = "C:\Users\gk\Documents\toread"


readfile= open(pathfile+'.txt', 'r')

I tried just to make a variable the as the redfile

newList = []
newList = readfile
readfile.close()

so then send in a fetch that list for a graph.

But I justs get a None when I generate a graph.

1 Answers

Just Try to use a for loop to save every line of the txt in the new list

pathfile = "C:\Users\gk\Documents\toread"


readfile= open(pathfile+'.txt', 'r')


newList = []

for i in readfile:
        newList.append(i)
readfile.close()

Related