【量化交易】 PrettyTable - 让你的日志数据更美观
每天尽量抽空学习、并截图样式案例方便自己记忆和查阅。
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