Welcome to EZPaths’s documentation!

class ezpaths.Path(path_str: Optional[str] = None)

This class provides shorthand methods for common os.path functions The motivation for development that complex one-liners with os.path can be hard to read. This is intended to make complex one-liners easy to understand without comments.

__init__(path_str: Optional[str] = None)

Constructor method

Parameters

path_str (str, optional) – The path string to be stored, defaults to None

__add__(other)ezpaths.path.Path

Creates the joined path appending other (RHS) to self. Does not modify self. Same as __truediv__.

Parameters

other (Either a Path or string) – The path segment to be joined

Returns

Returns the resulting Path object

Return type

Path

__truediv__(other)ezpaths.path.Path

Creates the joined path appending other (RHS) to self. Does not modify self. Same as __add__.

Parameters

other (Either a Path or string) – The path segment to be joined

Returns

Returns the resulting Path object

Return type

Path

__str__()str

Return the stored path string.

Returns

String of target path.

Return type

str

__repr__()str

Returns the type and path string in instance brackets.

Returns

String representation of self.

Return type

str

__bool__()bool

Checks if path exists as either a file or directory.

Returns

True if exists else False.

Return type

bool

__eq__(other)bool

Checks if the absolute path of self and other are identical.

Parameters

other (Either a Path or string) – The path to be compared

Returns

True if identical paths else False

Return type

bool

dir(extra: int = 0)ezpaths.path.Path

Returns path object targeting parent directory of self.

Parameters

extra (int, optional) – Number of extra levels to ascend recursively, defaults to 0

Returns

The parent directory path

Return type

Path

dirname()str

Returns the name of the last directory, with or without file at end of path.

Returns

The name of the last directory in self._path

Return type

str

split() -> (<class 'str'>, <class 'str'>)

Return name and extension separately.

Returns

The name and extension of the file.

Return type

tuple(name: str, ext: str)

ext()str

Returns just the file extension.

Returns

File extension

Return type

str

name()str

Returns the last file or dir name without extension.

Returns

Last file or dir name

Return type

str

filename()str

Returns the last file or dir name with extension.

Returns

Last file or dir name

Return type

str

to_sys(index: int = 0)None

Adds self to sys.path list. Will insert at front by default. Inserting at front makes it the first path checked when importing.

Parameters

index (int, optional) – Index to be inserted at in sys.path list, defaults to 0

Returns

None

Return type

None

__weakref__

list of weak references to the object (if defined)

Indices and tables