程式運行時 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)

相關內容