-
Notifications
You must be signed in to change notification settings - Fork 0
Usage (API Overview)
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| 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 |
A mutable_print instance that can be updated or transformed.
Update the content and reprint from this line onward.
line("Processing...", sep=" ", end="\n")| Name | Type | Default | Description |
|---|---|---|---|
*args |
Any |
— | New values to print |
sep |
str |
" " |
Separator |
end |
str |
"\n" |
End string |
Replace all (or a limited number of) occurrences of a substring in the current content.
line.replace("fail", "success", 1)| Name | Type | Default | Description |
|---|---|---|---|
old |
str |
— | Substring to replace |
new |
str |
— | Replacement text |
count |
int |
-1 |
Max occurrences (-1 for all) |
Append text to the end of the content.
line.append("...done")| Name | Type | Description |
|---|---|---|
*text |
str |
Text strings to append |
Prepend text to the beginning of the content.
line.prepend("[INFO]")| Name | Type | Description |
|---|---|---|
*text |
str |
Text strings to prepend |
Clear the current content (sets it to an empty string).
line.clear()Replace the entire content with new text.
line.set("New content")| Name | Type | Description |
|---|---|---|
*text |
str |
Text strings to set as new content |
Convert the current content to uppercase.
line.upper()Convert the current content to lowercase.
line.lower()Perform a regular expression substitution on the content.
line.regex_replace(r"\d+", "42")| 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) |
Retrieve the current content.
text = line.get()String representation of the current content. Called automatically by str(line).
Developer-friendly representation of the object:
mutable_print('Your content here')