new_filename

ndmapper.libutils.new_filename(purpose='tmp', base='', ext='', full_path=False)[source] [edit on github]

Generate a new filename string that is not already used in the current directory (beginning with ‘tmp’ by default, for use as a temporary file). Unlike Python’s tempfile module, this function does not actually open the file, making the result suitable for passing to external programs, but as a result, a race condition may occur if the file is not created immediately, which is the user’s responsibility.

Parameters:

purpose : str, optional

Starting string, used to indicate the file’s purpose (default ‘tmp’).

base : convertible to str, optional

A base name to add between “tmp_” and the last few, randomized characters, to help distinguish temporary filenames, eg. for troubleshooting purposes.

ext : convertible to str, optional

An file extension name to use (eg ‘fits’). The leading dot is optional and will be added if needed.

full_path : bool

Return the full path to the file, rather than a (relative) filename in the current working directory (default False)?

Returns:

str

A filename that doesn’t already exist in the current working directory.