How to create a self-deleting temporary directory in Python
Starting from Python 3.2 your can use tmpfile.TemporaryDirectory
like this:
from tempfile import TemporaryDirectory
with TemporaryDirectory(prefix="myapp-") as tmpdir:
print(tmpdir) # e.g. "/tmp/myapp-fevhzh93"
# Once you are outside the "with" block, the directory will be deleted!
In case you are stuck with using older Python versions, check out How to create temporary directory in Python.
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow