[issue31959] Directory at `TemporaryDirectory().name` does not exist

Serhiy Storchaka report at bugs.python.org
Mon Nov 6 07:38:04 EST 2017


Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:

This is by design. The first TemporaryDirectory object is destroyed before the first print statement. For not be surprised use TemporaryDirectory with the "with" statement.

with TemporaryDirectory() as td:
    name = td.name
    print(os.path.exists(name))  # prints True

print(os.path.exists(name))  # prints False

----------
nosy: +serhiy.storchaka
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue31959>
_______________________________________


More information about the Python-bugs-list mailing list