Python - File System Path

About

File System - Path in Python

Path definition can be found path-like-object

Library

Os.path

os.path

To create a path:

  • os.path Example with os.path to create a path from parts
os.path.join("output","log.txt")

Pathlib

Object-oriented filesystem paths

  • Concrete
from pathlib import Path
Path('setup.py') # a subclass of PurePath
  • Pure classes (They don’t have any OS-accessing operations)
PurePath('/etc', '/usr', 'lib64') # generic, it creates either a PurePosixPath or a PureWindowsPath
PurePosixPath('/etc') # non-Windows filesystem paths
PureWindowsPath('c:/Windows', 'd:bar') # Windows filesystem paths

Powered by ComboStrap