pathlib

Standard library module View source

Native filesystem paths represented by the immutable Path tuple class.

Lexical operations preserve .. components. Methods that change the filesystem do not change the stored path.

class Path
@tuple
class Path
Constructors 1
__new__
__new__(*segments)
Properties 10
drive
@property
drive(self)
root
@property
root(self)
anchor
@property
anchor(self)
parts
@property
parts(self)
name
@property
name(self)
suffix
@property
suffix(self)
suffixes
@property
suffixes(self)
stem
@property
stem(self)
parent
@property
parent(self)
parents
@property
parents(self)
Methods 48
joinpath
joinpath(self, *segments)
as_posix
as_posix(self)
with_name
with_name(self, name: str)
with_stem
with_stem(self, stem: str)
with_suffix
with_suffix(self, suffix: str)
is_absolute
is_absolute(self)
is_relative_to
is_relative_to(self, other)
relative_to
relative_to(self, other, walk_up: bool = False)
cwd
cwd()
home
home()
absolute
absolute(self)
resolve
resolve(self, strict: bool = False)
expanduser
expanduser(self)
as_uri
as_uri(self)
stat
stat(self, follow_symlinks: bool = True)
lstat
lstat(self)
exists
exists(self, follow_symlinks: bool = True)
is_file
is_file(self, follow_symlinks: bool = True)
is_dir
is_dir(self, follow_symlinks: bool = True)
is_socket
is_socket(self)
is_fifo
is_fifo(self)
is_block_device
is_block_device(self)
is_char_device
is_char_device(self)
is_mount
is_mount(self)
samefile
samefile(self, other)
open
open(self, mode: str = "r", encoding: Optional[str] = None, errors: Optional[str] = None, newline: Optional[str] = None)
open(self, mode: Literal[str], encoding: Optional[str] = None, errors: Optional[str] = None, newline: Optional[str] = None)
read_text
read_text(self, encoding: Optional[str] = None, errors: Optional[str] = None, newline: Optional[str] = None)
read_bytes
read_bytes(self)
write_text
write_text(self, data: str, encoding: Optional[str] = None, errors: Optional[str] = None, newline: Optional[str] = None)
write_bytes
write_bytes(self, data: bytes)
iterdir
iterdir(self)
mkdir
mkdir(self, mode: int = 0o777, parents: bool = False, exist_ok: bool = False)
rmdir
rmdir(self)
rename
rename(self, target)
replace
replace(self, target)
chmod
chmod(self, mode: int, follow_symlinks: bool = True)
lchmod
lchmod(self, mode: int)
touch
touch(self, mode: int = 0o666, exist_ok: bool = True)
match
match(self, pattern, case_sensitive: Optional[bool] = None)
full_match
full_match(self, pattern, case_sensitive: Optional[bool] = None)
glob
glob(self, pattern, case_sensitive: Optional[bool] = None, recurse_symlinks: bool = False)
rglob
rglob(self, pattern, case_sensitive: Optional[bool] = None, recurse_symlinks: bool = False)
walk
walk(self, top_down: bool = True, on_error = None, follow_symlinks: bool = False)
Special methods 12
__str__
__str__(self)
__repr__
__repr__(self)
__fspath__
__fspath__(self)
__hash__
__hash__(self)
__eq__
__eq__(self, other)
__ne__
__ne__(self, other)
__lt__
__lt__(self, other: Path)
__le__
__le__(self, other: Path)
__gt__
__gt__(self, other: Path)
__ge__
__ge__(self, other: Path)
__truediv__
__truediv__(self, other)
__rtruediv__
__rtruediv__(self, other)