python - 在 python 中创建 NamedTemporaryFile 时出现 ValueError

标签 python temporary-files

通过搜索现有问题尚未找到解决方案,这里是:

Python 的新手。尝试使用 tempfile 包创建临时文件。以下是因 ValueError 失败的代码行:

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

当我运行脚本时,我收到此 ValueError:

ValueError:需要超过 0 个值才能解压

为什么?

最佳答案

tempfile.NamedTemporaryFile() 不返回文件名,仅返回句柄。您需要访问 name 属性才能获取文件名。

关于python - 在 python 中创建 NamedTemporaryFile 时出现 ValueError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37333887/

相关文章:

python - 是否有 Python 等同于 Perl 的 __DATA__ 文件句柄?

python - Matplotlib x 轴重叠

c++ - var arg list to tempfile,为什么需要它?

python - 在布局中移动小部件 pyqt

python - 将坐标列表转换为元组列表

c# - 使用(FileStream)创建临时文件导致 "The process cannot access the file because it is being used"

powershell - 如何使用powershell删除所有临时文件

c++ - 如何创建临时文件以在 Linux 平台上用 C++ 编写?

c++ - Qt - 如何为任意用户获取 "Temp"目录?

python - 将文件读取到 Python 中的字符串列表