python tempfile.mkstemp()(一時ファイルを作成します)



Python Tempfile Mkstemp



def mkstemp(suffix=None, prefix=None, dir=None, text=False): '''User-callable function to create and return a unique temporary file. The return value is a pair (fd, name) where fd is the file descriptor returned by os.open, and name is the filename. A function called by the user to create and return a unique temporary file. The return value is a pair (fd, name), where fd is the file descriptor returned by os.open and name is the file name. If 'suffix' is not None, the file name will end with that suffix, otherwise there will be no suffix. If 'Suffix' is not 'None', the file name will end with the suffix, otherwise there will be no suffix. If 'prefix' is not None, the file name will begin with that prefix, otherwise a default prefix is used. If 'prefix' is not None, the file name will start with this prefix, otherwise the default prefix will be used. If 'dir' is not None, the file will be created in that directory, otherwise a default directory is used. If 'dir' is not None, the file will be created in that directory, otherwise the default directory will be used. If 'text' is specified and true, the file is opened in text mode. Else (the default) the file is opened in binary mode. On some operating systems, this makes no difference. If 'text' is specified and true, the file is opened in text mode. Otherwise (default) the file is opened in binary mode. On some operating systems, this makes no difference. If any of 'suffix', 'prefix' and 'dir' are not None, they must be the same type. If they are bytes, the returned name will be bytes str otherwise. If any of 'suffix', 'prefix' and 'dir' are not None, they must be of the same type. If they are bytes, the name returned will be bytes otherwise, str. The file is readable and writable only by the creating user ID. If the operating system uses permission bits to indicate whether a file is executable, the file is executable by no one. The file descriptor is not inherited by children of this process. This file can only be read and written by the user ID created. If the operating system uses permission bits to indicate whether the file is executable, no one can execute the file. The child of this process will not inherit the file descriptor. Caller is responsible for deleting the file when done with it. After completion, the caller is responsible for deleting the file. (That is, it will not be deleted automatically) ''' prefix, suffix, dir, output_type = _sanitize_params(prefix, suffix, dir) if text: flags = _text_openflags else: flags = _bin_openflags return _mkstemp_inner(dir, prefix, suffix, flags, output_type)