每天儘量抽空學習、並截圖樣式案例方便自己記憶和查閱。
Python通過prettytable模塊可以將輸出內容如表格方式整齊的輸出。
使用該模塊,用戶可以在日誌中輸出清晰的日誌文檔。
官方鏈接:https://github.com/jazzband/prettytable當前如果paycharm 上使用的話
pip prettytable
PrettyTable介紹
Python通過prettytable模塊可以將輸出內容如表格方式整齊的輸出。
使用該模塊,用戶可以在日誌中輸出清晰的日誌文檔。
# ====================== 常用方法如下:===================
sortby - name of field to sort rows by reversesort - True or False to sort in descending or ascending order int_format - controls formatting of integer data float_format - controls formatting of floating point data add_row(row) """Add a row to the table Arguments: row - row of data, should be a list with as many elements as the table has fields""" del_row(row_index) """Delete a row to the table Arguments: row_index - The index of the row you want to delete. Indexing starts at 0.""" add_column(fieldname, column, align="c", valign="t") """Add a column to the table. Arguments: fieldname - name of the field to contain the new column of data column - column of data, should be a list with as many elements as the table has rows align - desired alignment for this column - "l" for left, "c" for centre and "r" for right valign - desired vertical alignment for new columns - "t" for top, "m" for middle and "b" for bottom""" clear_rows() """Delete all rows from the table but keep the current field names""" clear() """Delete all rows and field names from the table, maintaining nothing but styling options"""
# ====================================分割線結束=========================================
示例如下:
from prettytable import *
代碼樣式如下
詳細代碼案例鏈接:
https://www.joinquant.com/view/community/detail/f8156b4dec5a2b4404c52250f3ece028