CtrlK
CommunityDocumentationLog inGet started
Tessl Logo

tessl/pypi-tabulate

tessl install tessl/pypi-tabulate@0.9.0

Pretty-print tabular data in Python with extensive formatting options and output format support.

Agent Success

Agent success rate when using this tile

69%

Improvement

Agent success rate improvement when using this tile compared to baseline

0.9x

Baseline

Agent success rate without this tile

77%

task.mdevals/scenario-8/

Multilingual Product Catalog Formatter

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.

Requirements

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:

  1. Accept a list of product dictionaries, each containing:

    • id: Product ID (integer)
    • name: Product name (may contain CJK characters)
    • price: Price as a float
    • description: Short description (may contain CJK characters)
  2. Display the data in a grid-style table format with proper borders

  3. Correctly calculate character widths for alignment purposes:

    • CJK characters (Chinese, Japanese, Korean) should be treated as having width 2
    • ASCII characters should be treated as having width 1
    • The table columns must align properly regardless of character types
  4. Handle text wrapping for long descriptions:

    • Wrap descriptions that exceed 20 visible characters
    • Ensure wrapping respects character boundaries for wide characters

Implementation

@generates

Create a module with a format_catalog function that takes a list of product dictionaries and returns a formatted table string.

API

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
    """
    pass

Test Cases

Basic CJK character display

  • Given products with Chinese names like "智能手机" (smartphone), the table displays them with correct alignment @test

Input:

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

Mixed character widths

  • Given products mixing ASCII and Japanese characters, column alignment remains consistent @test

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

Long description wrapping

  • Given products with long Korean descriptions, text wraps at 20 visible characters while maintaining proper wide character boundaries @test

Input:

products = [
    {"id": 20, "name": "스마트워치", "price": 299.99, "description": "건강 추적 기능이 있는 최신 스마트워치"}
]

Expected: Description wraps correctly, respecting Korean character boundaries

Dependencies { .dependencies }

tabulate { .dependency }

Provides table formatting with wide character support.

wcwidth { .dependency }

Required for proper wide character width calculation.

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/tabulate@0.9.x
tile.json