Python: os.tmpfile or tempfile.mkstemp

I want to open an external config file and present it to the user in an editor.

The solution I'm thinking about is creating a temporary file and copying the contents of the original file to it. The temporary file will then be opened for user editing in the default editor. This is all done because an incorrect configuration should never be written to the source file.

When the user saves the changes and closes the editor, the python script checks to see if the changes are valid and only overwrites the original file if so.

I have done some research and there seem to be two possibilities for creating a temporary file in python:

os.tmpfile

      

and

tempfile.mkstemp

      

what is the difference between them? which one is better suited for this task? or is there a better way to do this?

thank

+3


source to share


1 answer


Use the tempfile module if only because it has better documentation and we know exactly what mkstemp () does



+2


source







All Articles