I am using the tempfile Python module to create a temporary file. I need to write to the file, and then I need to change the mode of the file so it is read-only (chmod 400). Is there a way I can do this using the tempfile module itself? Or should I look into using subprocess to achieve this? E.g subprocess.run(["chmod", "400", tmp_file.name])
Here's an example:
import tempfile
tmp_file = tempfile.NamedTemporaryFile() # by default this tempfile will have write permissions
tmp_file.write(b'Hello world!')
tmp_file.chmod(400) # I need to be able to change the permissions of the tempfile after I've written to it