INNER CODE UNIT · Python

print_table

dummylabs/thewatchman · cli/parser.py:29

def print_table(headers, data, max_width=None):
    if not data:
        print("No data found.")
        return

    # Calculate column widths
    widths = [len(h) for h in headers]
    for row in data:
        for i, val in enumerate(row):
            widths[i] = max(widths[i], len(str(val)))

    # Cap width if needed
    if max_width:
        widths = [min(w, max_width) for w in widths]

    # Create format string
    fmt = "  ".join([f"{{:<{w}}}" for w in widths])

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…