首页 > 解决方案 > 为什么 tempfile 和 os.chdir() 会抛出 RecursionError?

问题描述

import os, tempfile

with tempfile.TemporaryDirectory() as tempdir:
    os.chdir(tempdir)

为什么这会引发 RecursionError?首先,这段代码是如何递归的?我将如何将工作目录更改为临时目录?

标签: pythonpython-3.xrecursion

解决方案


实际的错误是这样的:The process cannot access the file because it is being used by another process

tempdir在删除之前需要更改工作目录。


推荐阅读