The pathlib
module handles file paths with support for different operating systems.
The example below uses pathlib to read text from a file.
>>> import pathlib
>>> pathlib.Path('myfile.txt').read_text()
'text contained in the file'
Get the file name from a given path.
>>> import pathlib
>>> file = '/Users/gavinw/Desktop/screenshot.png'
>>> pathlib.Path(file).name
'screenshot.png'
Pythonic Programming © 2024
Built by Gavin Wiggins