Skip to content

Usage (API Overview)

PcoiDev edited this page Oct 4, 2025 · 3 revisions

mutable_print

Creates a mutable print object, prints the initial content immediately, and returns a handle to modify it later.

from mutable_print import mutable_print

line = mutable_print("Loading...", flush=True)
line("Done!")  # Update the same printed line

Parameters

Name Type Default Description
*args Any Values to print
sep str " " Separator between values
end str "\n" String appended at the end
file TextIO sys.stdout Output stream
flush bool False Whether to flush immediately

Returns

A mutable_print instance that can be updated or transformed.


__call__

Update the content and reprint from this line onward.

line("Processing...", sep=" ", end="\n")

Parameters

Name Type Default Description
*args Any New values to print
sep str " " Separator
end str "\n" End string

replace

Replace all (or a limited number of) occurrences of a substring in the current content.

line.replace("fail", "success", 1)

Parameters

Name Type Default Description
old str Substring to replace
new str Replacement text
count int -1 Max occurrences (-1 for all)

append

Append text to the end of the content.

line.append("...done")

Parameters

Name Type Description
*text str Text strings to append

prepend

Prepend text to the beginning of the content.

line.prepend("[INFO]")

Parameters

Name Type Description
*text str Text strings to prepend

clear

Clear the current content (sets it to an empty string).

line.clear()

set

Replace the entire content with new text.

line.set("New content")

Parameters

Name Type Description
*text str Text strings to set as new content

upper

Convert the current content to uppercase.

line.upper()

lower

Convert the current content to lowercase.

line.lower()

regex_replace

Perform a regular expression substitution on the content.

line.regex_replace(r"\d+", "42")

Parameters

Name Type Default Description
pattern str | re.Pattern Regex pattern
replacement str Replacement string (supports backrefs)
flags int 0 Regex flags (e.g. re.IGNORECASE)

get

Retrieve the current content.

text = line.get()

__str__

String representation of the current content. Called automatically by str(line).


__repr__

Developer-friendly representation of the object:

mutable_print('Your content here')

Clone this wiki locally