Python 3.4 added path objects, but most people still don’t know about them. They simplify a lot of file operations: ### Without pathlibpath="path/to/file"# parent diros.path.dirname(path)# file suffixos.path.splitext(path)[1]# read filewithopen(path)asf:x=f.read()### With pathlibpath=pathlib.Path("path/to/file")# parent dirpath.parent# file suffixpath.suffix# read filex=path.read_text() Paths are also OS-independent, so the same code will generally work on both Windows and Unix.