TableLogger
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
-
ImportError: numpy.core.multiarray failed to import
cause This error, particularly after a NumPy upgrade to 2.0+, often indicates an ABI (Application Binary Interface) incompatibility. Python packages that use NumPy's C API and were built against an older NumPy version will not work with NumPy 2.0.fixReinstall `table-logger` and any other packages that depend on NumPy after upgrading NumPy. This ensures they are compiled against the new NumPy ABI. Example: `pip uninstall numpy table-logger && pip install numpy table-logger`. -
Table output not displaying correctly in Jupyter notebooks.
cause Older versions of `table-logger` had specific issues handling output streams in Jupyter environments.fixUpdate to `table-logger` version 0.3.5 or newer: `pip install --upgrade table-logger`. -
TypeError: 'numpy.float64' object is not callable or AttributeError: module 'numpy' has no attribute 'float'
cause This typically occurs if your `table-logger` version is older and attempts to use deprecated NumPy aliases like `np.float` or `np.int`, which have been removed in newer NumPy versions. Version 0.3.7 of `table-logger` explicitly removed its internal use of these.fixUpgrade `table-logger` to 0.3.7 (once available on PyPI) or ensure your code is using modern NumPy types (e.g., `float` or `int` directly) and that all dependent libraries are compatible with your NumPy version.
Warnings
- breaking Version 0.3.7 (GitHub release) removed deprecated `numpy` aliases `np.float` and `np.int`. If you are using an older version of `table-logger` with a very new `numpy` version (e.g., NumPy 2.0+), or your code relies on these aliases in conjunction with `table-logger`, you may encounter errors related to these removed types.
- gotcha Prior to version 0.3.5, users reported logging issues when `table-logger` was used within Jupyter notebooks, where output might not display correctly or consistently.
- gotcha NumPy 2.0 (released June 2024) introduced significant breaking changes, including an ABI break and API cleanups. If `table-logger` (or other libraries it depends on) was compiled against an older NumPy 1.x version and then run with NumPy 2.0, this can lead to `ImportError` due to binary incompatibility.
Install
-
pip install table-logger
Imports
- TableLogger
from table_logger import TableLogger
Quickstart
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()