December 2018
Beginner to intermediate
796 pages
19h 54m
English
Let's explore a little more the abilities of os.path by means of a simple example:
# files/paths.pyimport osfilename = 'fear.txt'path = os.path.abspath(filename)print(path)print(os.path.basename(path))print(os.path.dirname(path))print(os.path.splitext(path))print(os.path.split(path))readme_path = os.path.join( os.path.dirname(path), '..', '..', 'README.rst')print(readme_path)print(os.path.normpath(readme_path))
Reading the result is probably a good enough explanation for this simple example:
/Users/fab/srv/lpp/ch7/files/fear.txt # pathfear.txt # basename/Users/fab/srv/lpp/ch7/files # dirname('/Users/fab/srv/lpp/ch7/files/fear', '.txt') # splitext('/Users/fab/srv/lpp/ch7/files', 'fear.txt') # split/Users/fab/srv/lpp/ch7/files/../../README.rst ...Read now
Unlock full access