cf.tempdir

cf.tempdir(*arg)[source]

The directory for internally generated temporary files.

When setting the directory, it is created if the specified path does not exist.

Parameters:
arg: str, optional

The new directory for temporary files. Tilde expansion (an initial component of ~ or ~user is replaced by that user’s home directory) and environment variable expansion (substrings of the form $name or ${name} are replaced by the value of environment variable name) are applied to the new directory name.

The default is to not change the directory.

Returns:
Constant

The directory name prior to the change, or the name of the current directory if no new value was specified.

Examples

>>> print(cf.tempdir())
'/tmp'
>>> old = cf.tempdir('/home/me/tmp')
>>> print(cf.tempdir(old))
'/home/me/tmp'
>>> print(cf.tempdir())
'/tmp'
>>> with cf.tempdir('~/NEW_TMP'):
...     print(cf.tempdir())
...
/home/me/NEW_TMP
>>> print(cf.tempdir())
'/tmp'