python3 create new empty file

Solution

You need to create an empty file with python3. The proper way to create a new file is by using the pathlib module. Pathlib has the Path object which allows you to manipulate the filesystem.

Here is an example on how to touch a file with python3:

from pathlib import Path
Path('empty_file').touch()

Remember to initialize Path with the path to the file you want to create.

Leonardo Lazzaro

Software engineer and technical writer. 10+ years experience in DevOps, Python, and Linux systems.

More articles by Leonardo Lazzaro