import tempfile, pathlib with tempfile.TemporaryDirectory() as d: tmp = pathlib.Path(d) # tmp 下做所有中間產物