Machen Sie das Wörterbuch zu einer leicht lesbaren Tabelle
table_printer.py
# -*- coding: utf-8 -*-
from table_printer import TablePrinter
fmt = [
('Title', 'title', 20, 'left'),
('Description', 'description', 20, 'right'),
]
data = [{'title': 'Hello', 'description': 'World'}]
totals = {'title': 'TOTAL', 'description': '1 title'}
print TablePrinter(fmt, sep='|', ul='=', tl='-', bl='_')(data, totals)
table_printer.txt
--------------------|--------------------
Title | Description
====================|====================
Hello | World
====================|====================
TOTAL | 1 title
____________________|____________________
Recommended Posts