How do I persist to disk a temporary file using Python?

前端 未结 4 2038
难免孤独
难免孤独 2021-02-02 09:35

I am attempting to use the \'tempfile\' module for manipulating and creating text files. Once the file is ready I want to save it to disk. I thought it would be as simple as usi

4条回答
  •  悲哀的现实
    2021-02-02 10:19

    You could always use shutil.copyfileobj, in your example:

    new_file = open('bar.txt', 'rw')
    shutil.copyfileobj(f, new_file)
    

提交回复
热议问题