Hướng dẫn how to create a table from a dictionary in python - cách tạo bảng từ từ điển trong python

Tôi đang tìm kiếm một giải pháp với chiều rộng không xác định để in bảng cơ sở dữ liệu. Vì vậy, đây là:

def printTable[myDict, colList=None]:
   """ Pretty print a list of dictionaries [myDict] as a dynamically sized table.
   If column names [colList] aren't specified, they will show in random order.
   Author: Thierry Husson - Use it as you want but don't blame me.
   """
   if not colList: colList = list[myDict[0].keys[] if myDict else []]
   myList = [colList] # 1st row = header
   for item in myDict: myList.append[[str[item[col] if item[col] is not None else ''] for col in colList]]
   colSize = [max[map[len,col]] for col in zip[*myList]]
   formatStr = ' | '.join[["{{:

Bài Viết Liên Quan

Chủ Đề