python-fhs
Python module for using the FHS and XDG basedir paths.
Loading...
Searching...
No Matches

◆ write_temp()

fhs.write_temp (   dir = False,
  text = True,
  packagename = None 
)

Open a temporary file for writing.

The file is automatically removed when the program exits. If this function is used in a with statement, the file is removed when the statement finishes.

Unlike other write_* functions, this one has no option to get the filename without opening the file, because that is a security risk for temporary files. However, the returned object is really a wrapper that looks like a file, but has one extra attribute: "filename". This can be used in cases where for other file types "opened = False" would be appropriate. It also has an extra method: "remove". This takes no arguments and removes the file immediately. "remove" should not be called multiple times.

Parameters
dirIf False (the default), a file is created. If True, a directory is created and the name is returned. On remove, the directory contents are recursively removed.
textIf True (the default), the file is opened in text mode. This parameter is ignored if dir is True.
packagenameOverride the packagename.
Returns
The file, or the name of the directory.

Definition at line 892 of file fhs.py.

Here is the caller graph for this function: