[OnePoint Python] pathlib, shutil, tempfile

A simple example of Python modules that are often used but seem difficult.

A Ydobon
1 min readSep 1, 2020

Some python modules are useful yet seem difficult.

  • pathlib — Object-oriented filesystem paths
  • tempfile — Generate temporary files and directories
  • shutil — High-level file operations

The following example makes a new temporary directory logdir and delete all files and sub-directories under logdir .

import pathlib
import shutil
import tempfile
logdir = pathlib.Path(tempfile.mkdtemp())/"tensorboard_logs"
shutil.rmtree(logdir, ignore_errors=True)

--

--

A Ydobon
A Ydobon

No responses yet