【问题标题】:Issue importing Python tempfile module导入 Python tempfile 模块的问题
【发布时间】:2013-08-14 20:56:11
【问题描述】:

我正在尝试创建临时文件,但我的 python 版本不允许我继续并提出以下投诉。 我是否需要升级此版本才能使用 tempfile 模块。 谢谢

Python 2.4.3 (#1, Jan  9 2013, 06:47:03) [GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tempfile
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "tempfile.py", line 2, in ?
    temp = tempfile.NamedTemporaryFile()
AttributeError: 'module' object has no attribute 'NamedTemporaryFile'

【问题讨论】:

    标签: python temporary-files


    【解决方案1】:

    您正在导入 本地 文件。您的本地目录中有一个名为 tempfile.py 的文件,它掩盖了全局模块。 import tempfile 导入该文件,而不是标准库模块。

    如果找不到该文件,请使用print tempfile.__file__ 查找该文件。将该文件重命名为其他名称。

    Python 2.4 tempfile module 无需升级即可支持NamedTemporaryFile

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-26
      • 1970-01-01
      • 1970-01-01
      • 2019-07-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多