程序运行时,TemporaryDirectory() 会抛出属性错误

程序运行时,TemporaryDirectory() 会抛出属性错误

我正在尝试使用创建一个临时目录with tempfile.TemporaryDirectory() as directory:

我已经导入了临时文件

当我运行该程序时出现错误:

Traceback (most recent call last):
  File "batch.py", line 79, in <module>
    with tempfile.TemporaryDirectory() as directory:
AttributeError: 'module' object has no attribute 'TemporaryDirectory'

我正在运行 python 3.8

如果使用调试器运行,程序将成功运行,但是当我不使用调试器运行它时,我收到此错误。

完整代码:

with tempfile.TemporaryDirectory() as directory:
   for subdir, dirs, files in os.walk(rootdir):
      if subdir != rootdir and subdir != fDestination and subdir != meDir 
      and subdir != fileDestination and subdir != zdir:
         shutil.move(subdir, directory)

相关内容