TableLogger

0.3.6 · active · verified Thu Apr 16

TableLogger is a Python utility designed for logging tabular data to either a console or a file. It provides features like sane default formatting for standard Python types, automatically includes row numbers, timestamps, and time deltas, and supports CSV output. Users can also customize column widths and formatting. The library is currently active, with version 0.3.6 being the latest official release on PyPI, though recent GitHub activity shows version 0.3.7. The release cadence appears to be infrequent based on PyPI update history.

Common errors

Warnings

Install

Imports

Quickstart

Initialize a TableLogger instance with specified columns and then log rows. The `flush()` method is implicitly called when the object is garbage collected or the program exits, but can be called explicitly to ensure output. Examples also show enabling row numbers, timestamps, and time deltas.

from table_logger import TableLogger
from datetime import datetime
import math
import random

tbl = TableLogger(columns='a,b,c,d')
tbl(1, 'Row1', datetime.now(), math.pi)
tbl(2, 'Row2', datetime.now(), 1/3)
tbl(3, 'Row3', datetime.now(), random.random())

# Example with additional columns
import time
tbl_extended = TableLogger(columns='data', rownum=True, time_delta=True, timestamp=True)
for e in 'abcde':
    time.sleep(random.uniform(0.1, 0.5)) # Use uniform for more realistic varying delays
    tbl_extended(e)

print('\nStandard Table:')
tbl.flush()
print('\nExtended Table:')
tbl_extended.flush()

view raw JSON →