Copy the last three lines of a text file in python?

前端 未结 5 1777
故里飘歌
故里飘歌 2020-12-17 03:40

I\'m new to python and the way it handles variables and arrays of variables in lists is quite alien to me. I would normally read a text file into a vector and then copy the

5条回答
  •  自闭症患者
    2020-12-17 04:08

    A possible solution:

    lines = [ l for l in open("Output.txt")]
    file = open('Output.txt', 'w')
    file.write(lines[-3:0])
    file.close()
    

提交回复
热议问题