Copying from one text file to another using Python

前端 未结 8 1856
死守一世寂寞
死守一世寂寞 2020-11-30 01:56

I would like to copy certain lines of text from one text file to another. In my current script when I search for a string it copies everything afterwards, how can I copy jus

8条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-30 02:31

    If all of that did not work try this.

    with open("hello.txt") as f:
    with open("copy.txt", "w") as f1:
        for line in f:
            f1.write(line)
    

提交回复
热议问题