How do I copy a file in Python?

前端 未结 16 2222
隐瞒了意图╮
隐瞒了意图╮ 2020-11-21 07:12

How do I copy a file in Python?

I couldn\'t find anything under os.

16条回答
  •  醉话见心
    2020-11-21 07:31

    For large files, what I did was read the file line by line and read each line into an array. Then, once the array reached a certain size, append it to a new file.

    for line in open("file.txt", "r"):
        list.append(line)
        if len(list) == 1000000: 
            output.writelines(list)
            del list[:]
    

提交回复
热议问题