是临时文件以及tempfile.NamedTemporaryFile在Python>3中相同

2024-06-11 04:44:32 发布

您现在位置:Python中文网/ 问答频道 /正文

想想这个

import tempfile

print(help(tempfile.TemporaryFile))
print(help(tempfile.NamedTemporaryFile))

以上两个语句给出的结果与输出相同,它们是否属于同一个名为dtemporaryfile的类

^{pr2}$

同样,在上面的代码中,这两个类期望相同的命名/关键字参数在Python>;3中是相同的吗???在


Tags: 代码importgt参数help关键字语句tempfile
1条回答
网友
1楼 · 发布于 2024-06-11 04:44:32

那要看你的平台了。当我读https://github.com/python/cpython/blob/eb126eddbd7542ac9d7cd2736116aee2e0bd03dd/Lib/tempfile.py#L560中的代码时

if _os.name != 'posix' or _os.sys.platform == 'cygwin':
    # On non-POSIX and Cygwin systems, assume that we cannot unlink a file
    # while it is open.
    TemporaryFile = NamedTemporaryFile

对于非posix(linux等)环境或cygwin,这些方法是相同的。在

相关问题 更多 >