Copy a file line by line in python

前端 未结 4 1562
半阙折子戏
半阙折子戏 2021-01-12 17:48

I am writing a python program to copy a file line by line into a new file. The code I have is below in which I am using a loop to copy the file line by line.

Howeve

4条回答
  •  借酒劲吻你
    2021-01-12 18:37

    Files can be iterated directly, without the need for an explicit call to readline:

    f = open("...", "r")
    copy = open("...", "w")
    for line in f:
        copy.write(line)
    f.close()
    copy.close()
    

提交回复
热议问题