Python Tutorials - Herong's Tutorial Examples - v2.15, by Herong Yang
"pathlib.Path" - Read and Write Operations
This section describes methods from the 'pathlib.Path' class for file read and write operations.
"pathlib.Path" class also offers a number of methods to perform read and write operations on files:
Here are examples on how to use above pathlib.Path methods.
>>> from pathlib import Path
# Loop through child items of a directory
>>> p = Path('docs')
>>> for child in p.iterdir(): child
...
PosixPath('docs/conf.py')
PosixPath('docs/_templates')
PosixPath('docs/make.bat')
PosixPath('docs/index.rst')
PosixPath('docs/_build')
PosixPath('docs/_static')
PosixPath('docs/Makefile')
# write text, rename and read text on a file.
>>> p = Path('foo')
>>> p.write_text('some text')
9
>>> target = Path('bar')
>>> p.rename(target)
PosixPath('bar')
>>> target.read_text()
'some text'
>>> target.unlink()
Table of Contents
Variables, Operations and Expressions
Function Statement and Function Call
List, Set and Dictionary Comprehensions
Packages and Package Directories
►"pathlib" - Object-Oriented Filesystem Paths
"pathlib.Path" - Path for Both Linux and Windows
►"pathlib.Path" - Read and Write Operations
"pip" - Package Installer for Python
SciPy.org - Python Libraries for Science
pandas - Data Analysis and Manipulation
Anaconda - Python Environment Manager