简体   繁体   English

导入Python临时文件模块时出现问题

[英]Issue importing Python tempfile module

I am trying to create tempfile but my python versions do not allow me to proceed and give the following complaints. 我正在尝试创建tempfile,但是我的python版本不允许我继续进行操作并提出以下投诉。 Do I need to upgrade this version to use tempfile module. 我是否需要升级此版本才能使用tempfile模块。 Thanks 谢谢

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'

You are importing a local file. 您正在导入本地文件。 You have a file named tempfile.py in your local directory that masks the global module. 您的本地目录中有一个名为tempfile.py ,该文件掩盖了全局模块。 import tempfile imports that file, not the standard library module. import tempfile导入该文件,而不是标准库模块。

Use print tempfile.__file__ to locate that file if you cannot find it. 如果找不到该文件,请使用print tempfile.__file__查找该文件。 Rename that file to something else. 将该文件重命名为其他名称。

The Python 2.4 tempfile module supports NamedTemporaryFile without upgrading. Python 2.4 tempfile模块无需升级即可支持NamedTemporaryFile

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

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