Pretty-print tabular data in Python with extensive formatting options and output format support.
Overall
score
69%
Build a product catalog formatter that displays product information in a formatted table, with proper support for product names and descriptions in multiple languages including Chinese, Japanese, and Korean.
Create a Python script that reads product data and formats it into a well-aligned table that correctly handles wide characters (CJK characters). The formatter must:
Accept a list of product dictionaries, each containing:
id: Product ID (integer)name: Product name (may contain CJK characters)price: Price as a floatdescription: Short description (may contain CJK characters)Display the data in a grid-style table format with proper borders
Correctly calculate character widths for alignment purposes:
Handle text wrapping for long descriptions:
@generates
Create a module with a format_catalog function that takes a list of product dictionaries and returns a formatted table string.
def format_catalog(products: list[dict]) -> str:
"""
Format a product catalog with proper wide character support.
Args:
products: List of product dictionaries with keys: id, name, price, description
Returns:
A formatted table string with proper alignment for wide characters
"""
passInput:
products = [
{"id": 1, "name": "智能手机", "price": 599.99, "description": "高性能处理器"},
{"id": 2, "name": "Laptop", "price": 899.99, "description": "Powerful computing"}
]Expected: A properly aligned table where the Chinese characters don't cause misalignment
Input:
products = [
{"id": 10, "name": "ノートパソコン", "price": 1200.50, "description": "最新モデル"},
{"id": 11, "name": "Mouse", "price": 25.99, "description": "Wireless"}
]Expected: Proper alignment despite different character widths
Input:
products = [
{"id": 20, "name": "스마트워치", "price": 299.99, "description": "건강 추적 기능이 있는 최신 스마트워치"}
]Expected: Description wraps correctly, respecting Korean character boundaries
Provides table formatting with wide character support.
Required for proper wide character width calculation.
Install with Tessl CLI
npx tessl i tessl/pypi-tabulatedocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10