我试图使用tempfile.mkdtemp()
方法创建一个临时目录,但是我得到了以下错误
Traceback (most recent call last):
File "src/main.py", line 29, in <module>
tmp = tempfile.mkdtemp()
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/V
ersions/2.7/lib/python2.7/tempfile.py", line 331, in mkdtemp
dir = gettempdir()
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/V
ersions/2.7/lib/python2.7/tempfile.py", line 275, in gettempdir
tempdir = _get_default_tempdir()
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/V
ersions/2.7/lib/python2.7/tempfile.py", line 200, in _get_default_tem
pdir
with _io.open(fd, 'wb', closefd=False) as fp:
AttributeError: 'module' object has no attribute 'open'
使用python2.7.6和2.7.11运行此代码时
^{pr2}$我做错什么了?在
在我的目录中有一个名为
io.py
的文件,重命名该文件可以解决名称隐藏陷阱导致的问题。在See more here,谢谢J.F. Sebastian
在Python2.7.11中运行完全相同的脚本时,没有出现任何错误。也许您可以尝试打印临时文件夹的名称,以确保它创建正确(在删除之前)
相关问题 更多 >
编程相关推荐