The ‘
os.path
’ sub-module
The sub-module os.path contains further functionality that applies to file-system paths.
The term path refers to a particular location of a file, directory or link within the
hierarchical organisation of a file system, e.g. on a hard disk or DVD. All the functionality
presented here works on strings to represent the file-system paths, e.g.
‘/home/user/file.py’. Given that Python strings are immutable, the relevant methods will
generate new path strings etc. rather than modify existing ones. All of the examples below
assume the appropriate import has been made in the form: from os.path import method,
although we do not mean to preclude other import styles. From Python 3.4 there is a
module, pathlib, which provides an object-oriented approach to file paths.
Do'stlaringiz bilan baham: |