I want to open a external configuration file and present it to the user in an editor.
The solution I am thinking about is to create a temporary file and copy the content of the original file to it. The temporary file will then be opened for editing by the user in the default editor. This is all done because an incorrect configuration should never be written to the original file.
When the user saves the changes and closes the editor, the python script will check if the changes are acceptable, and only overwrite the original file if that is the case.
I have done some research and there seems to be two possibilities of creating a temporary file in python:
os.tmpfile
and
tempfile.mkstemp
what is the difference between them? which one is better suited for the task? or is there a better way of doing this?
Thanks
Use the tempfile module, if only for the reason that it's documentation is better and we know exactly what mkstemp() is doing