reprint

raw JSON →
0.6.0 verified Fri May 01 auth: no python maintenance

A simple module for Python 2/3 to print and refresh multi-line output contents in terminal. Version 0.6.0 is the latest, currently in maintenance mode.

pip install reprint
error AttributeError: module 'reprint' has no attribute 'output'
cause Incorrect import: using 'import reprint' then calling 'reprint.output'
fix
Correct import: from reprint import output
error IndexError: list assignment index out of range
cause Trying to update an index that exceeds the number of lines defined by 'initial_len'
fix
Set 'initial_len' to the number of lines you will modify, or modify only existing indices.
error ValueError: I/O operation on closed file.
cause Attempting to modify output_lines after the 'with' block has exited
fix
Ensure all modifications to output_lines are made within the 'with' block.
gotcha The 'output' context manager must be used with a 'with' statement. Assigning to output_lines indices without the proper context will cause undefined behavior or errors.
fix Always use 'with output(initial_len=..., interval=...) as output_lines:' and modify output_lines within the block.
gotcha The 'initial_len' parameter is optional but if not set, the output may not have enough lines. Attempting to access an index beyond the current number of lines will raise an IndexError.
fix Set 'initial_len' to the maximum number of lines you intend to update, or ensure you only update indices within range.
deprecated Python 2 support is not actively maintained. The library may work but is not guaranteed to receive bug fixes for Python 2.
fix Use Python 3 for best compatibility.
gotcha The 'interval' parameter controls refresh rate. Setting it too low (e.g., 0) may cause high CPU usage or terminal flickering.
fix Use a reasonable interval (>= 0.05) to avoid performance issues.

Creates a dynamic multi-line output that refreshes in place. The 'initial_len' sets the number of lines; assign to list indices to update.

import time
from reprint import output

with output(initial_len=3, interval=0.1) as output_lines:
    for i in range(10):
        output_lines[0] = f"Line 1: {i}"
        output_lines[1] = f"Line 2: {i*2}"
        output_lines[2] = f"Line 3: {i*3}"
        time.sleep(0.5)