txt

Classes

TxtReader

Safe text file reader.

TxtWriter

Safe text file writer.

class TxtReader[source]

Bases: object

Safe text file reader.

static check(path)[source]

Checks that a file has the correct extension and exists.

Parameters:

path (Union[str, Path]) – Path to the file.

Returns:

static read(path, verbose=True)[source]

Reads and parses a text file. :type path: Union[str, Path] :param path: Path to the file. :type verbose: Union[bool, int] :param verbose: Verbosity of the method. :rtype: str :return: Text content.

Parameters:
  • path (str | Path)

  • verbose (bool | int)

Return type:

str

class TxtWriter[source]

Bases: object

Safe text file writer.

static check(path, overwrite=False)[source]

Checks that a file has the correct extension. :type path: Union[str, Path] :param path: Path to the file. :return:

Parameters:
  • path (str | Path)

  • overwrite (bool)

static write(content, path, overwrite=False)[source]

Writes text content into a text file.

Parameters:
  • content (str) – Text content.

  • path (Union[str, Path]) – Path to the file.

  • overwrite (bool) – Whether to overwrite, in case of an existing file.

Returns: