Is there a way to read a .txt file and store each line to memory?

后端 未结 6 754
野趣味
野趣味 2021-02-06 02:48

I am making a little program that will read and display text from a document. I have got a test file which looks like this:

12,12,12
12,31,12
1,5,3
...
         


        
6条回答
  •  不知归路
    2021-02-06 02:56

    Thanks for @PePr excellent solution. In addition, you can try to print the .txt file with the built-in method String.join(data). For example:

    with open(filename) as f:
        data = f.readlines()
    print(''.join(data))
    

提交回复
热议问题