Python:禁止在关闭时删除临时文件

Python:禁止在关闭时删除临时文件,python,Python,我需要创建一个临时文件,其中包含一些测试内容: def test_something(): tmp\u path=make\u temp\u文件('hello\nworld') 做点什么(tmp路径) 但我使用以下代码使文件在关闭时自动删除文件: def make_temp_文件(文本): 使用tempfile.NamedTemporaryFile()作为tmp_文件: tmp_file.write(text.encode('utf-8')) tmp_file.flush() 返回tmp_fi

我需要创建一个临时文件,其中包含一些测试内容:

def test_something():
tmp\u path=make\u temp\u文件('hello\nworld')
做点什么(tmp路径)
但我使用以下代码使文件在关闭时自动删除文件:

def make_temp_文件(文本):
使用tempfile.NamedTemporaryFile()作为tmp_文件:
tmp_file.write(text.encode('utf-8'))
tmp_file.flush()
返回tmp_file.name
因此,在
do\u something(tmp\u路径)
中找不到该文件。如何防止在关闭时删除tmp文件?我将在测试后手动删除它。

有一个默认为true的。因此,示例中的代码应该是
tempfile.NamedTemporaryFile(delete=False)


感谢@juanpa.arrivillaga.

默认为true。谢谢,它成功了!