libs

Python temporary file

August 2, 2020
python, programming, libs

tags Python Programming Python’s tempfile standard library is pretty neat when we need to create a temporary file and/or directories. Instead of having a much of code like this: import pathlib def create_file(filename): if pathlib.Path(filename).exists(): # handle path removal/rewrite/backup pass with open(filename, "w") as f: # write to file pass We can ask Python to take care of handling this type of tasks for us. tempfile handles most of the OS API, so we can focus on writting the logic instead. ...