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.
用户调用的函数,用于创建并返回唯一的临时文件。
返回值是一对(fd,name),其中fd是os.open返回的文件描述符,name是文件名。
If 'suffix' is not None, the file name will end with that 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.
如果'prefix'不为None,则文件名将以该前缀开头,否则将使用默认前缀。
If 'dir' is not None, the file will be created in that directory,
otherwise a default directory is used.
如果“ dir”不是None,则将在该目录中创建文件,否则将使用默认目录。
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.
如果指定了'text'且为true,则以文本模式打开文件。
否则(默认)该文件以二进制模式打开。 在某些操作系统上,这没有区别。
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.
如果“后缀”,“前缀”和“ dir”中的任何一个都不为None,则它们必须是同一类型。
如果它们是字节,则返回的名称将是字节; 否则为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.
该文件只能由创建用户ID来读写。
如果操作系统使用权限位指示文件是否可执行,则该文件无人可执行。
该进程的子级不会继承文件描述符。
Caller is responsible for deleting the file when done with it.
完成后,调用方负责删除文件。(就是它自己不会自动删除)
"""
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)
python tempfile.mkstemp() (创建临时文件)
最新推荐文章于 2024-07-22 17:36:03 发布