简体   繁体   English

在python中创建NamedTemporaryFile时获取ValueError

[英]Getting a ValueError when making a NamedTemporaryFile in python

haven't found a solution to this through searching existing questions, here goes: 尚未通过搜索现有问题找到解决方案,请按以下步骤进行:

New-ish to python. python新手。 Trying to make a temporary file using the tempfile package. 尝试使用tempfile软件包制作一个临时文件。 Here is the line of code that is failing with a ValueError : 这是发生ValueError失败的代码行:

(temp_file, self.bucket) = tempfile.NamedTemporaryFile(suffix='.py', prefix='Custom_', dir=[mydir], delete=False)

I'm getting this ValueError when I run my script: 运行脚本时出现此ValueError:

ValueError: need more than 0 values to unpack

Why? 为什么?

tempfile.NamedTemporaryFile() doesn't return the filename, only the handle. tempfile.NamedTemporaryFile()不返回文件名,仅返回句柄。 You need to access the name attribute in order to get the filename. 您需要访问name属性以获取文件名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM