Skip to content

file_processing

File reading and writing actions.

CLASS DESCRIPTION
IncrementalFileInsert

Replace the start of a file with text.

ReadFile

Return a file’s contents when called.

WriteFile

Write the passed string to a file when called.

FUNCTION DESCRIPTION
stdout

Write content to stdout.

Attributes

Classes

IncrementalFileInsert dataclass

IncrementalFileInsert(
    filename: StrOrCallable, last_heading_pattern: StrOrCallable
)

Replace the start of a file with text.

METHOD DESCRIPTION
__call__

Replace the beginning of the file up to last_heading_pattern with input_text .

ATTRIBUTE DESCRIPTION
filename

The file name to write when called.

TYPE: StrOrCallable

last_heading_pattern

A regular expression to detect the last heading. Content before this position is re-rendered and inserted.

TYPE: StrOrCallable

Attributes

filename instance-attribute
filename: StrOrCallable

The file name to write when called.

last_heading_pattern instance-attribute
last_heading_pattern: StrOrCallable

A regular expression to detect the last heading. Content before this position is re-rendered and inserted.

Functions

__call__
__call__(input_text: StrOrCallable) -> StrOrCallable

Replace the beginning of the file up to last_heading_pattern with input_text .

PARAMETER DESCRIPTION
input_text

The text to insert.

TYPE: StrOrCallable

RETURNS DESCRIPTION
StrOrCallable

The same input_text

ReadFile dataclass

ReadFile(filename: StrOrCallable, create_if_missing: bool = True)

Return a file’s contents when called.

METHOD DESCRIPTION
__call__

Return the contents of the file.

ATTRIBUTE DESCRIPTION
create_if_missing

When True, create a missing file. Otherwise returns an error.

TYPE: bool

filename

The file name to read when called.

TYPE: StrOrCallable

Attributes

create_if_missing class-attribute instance-attribute
create_if_missing: bool = True

When True, create a missing file. Otherwise returns an error.

filename instance-attribute
filename: StrOrCallable

The file name to read when called.

Functions

__call__
__call__(*args, **kwargs) -> str

Return the contents of the file.

WriteFile dataclass

WriteFile(filename: StrOrCallable)

Write the passed string to a file when called.

METHOD DESCRIPTION
__call__

Writes input_text to the pre-configured file.

ATTRIBUTE DESCRIPTION
filename

The file name to write when called.

TYPE: StrOrCallable

Attributes

filename instance-attribute
filename: StrOrCallable

The file name to write when called.

Functions

__call__
__call__(input_text: StrOrCallable) -> StrOrCallable

Writes input_text to the pre-configured file.

Functions

stdout

stdout(content: str) -> str

Write content to stdout.