none 的漂亮规则和规则
Prettytable vrules and hrules to none
我有以下生成漂亮 table 的代码。我想做的是删除 vrules 或 hrules。我的代码没有做任何事情。你能告诉我为什么吗?只是为了确保,vrules 是垂直线
from prettytable import PrettyTable, FRAME, HEADER, NONE
PrettyTable().hrules = NONE
# x = PrettyTable()
# x.hrules = NONE
myTable = PrettyTable(["Student Name", "Class", "Section", "Percentage"])
myTable.title = 'Big Bang Theory'
# Add rows
myTable.add_row(["Leanord", "X", "B", "91.2 %"])
myTable.add_row(["Penny", "X", "C", "63.5 %"])
myTable.add_row(["Howard", "X", "A", "90.23 %"])
myTable.add_row(["Bernadette", "X", "D", "92.7 %"])
myTable.add_row(["Sheldon", "X", "A", "98.2 %"])
myTable.add_row(["Raj", "X", "B", "88.1 %"])
myTable.add_row(["Amy", "X", "B", "95.0 %"])
PrettyTable().vrules = NONE
print(myTable.get_string(sort_key=operator.itemgetter(1, 3), sortby="Section"))
它仍在生产相同的 table:
+---------------------------------------------+
| Big Bang Theory |
+--------------+-------+---------+------------+
| Student Name | Class | Section | Percentage |
+--------------+-------+---------+------------+
| Amy | X | B | 95.0 % |
| Bernadette | X | D | 92.7 % |
| Howard | X | A | 90.23 % |
| Leanord | X | B | 91.2 % |
| Penny | X | C | 63.5 % |
| Raj | X | B | 88.1 % |
| Sheldon | X | A | 98.2 % |
+--------------+-------+---------+------------+
根据 docs 你可以:
>>> myTable = PrettyTable()
>>> myTable.hrules, myTable.vrules = NONE, NONE
>>> myTable.title = 'Big Bang Theory' # this won't show, see below
>>> myTable.field_names = ["Student Name", "Class", "Section", "Percentage"]
>>> myTable.add_row(["Leanord", "X", "B", "91.2 %"])
>>> myTable.add_row(["Penny", "X", "C", "63.5 %"])
>>> myTable.add_row(["Howard", "X", "A", "90.23 %"])
>>> myTable.add_row(["Bernadette", "X", "D", "92.7 %"])
>>> myTable.add_row(["Sheldon", "X", "A", "98.2 %"])
>>> myTable.add_row(["Raj", "X", "B", "88.1 %"])
>>> myTable.add_row(["Amy", "X", "B", "95.0 %"])
>>> print(myTable.get_string(sort_key=operator.itemgetter(1, 3), sortby="Section"))
Student Name Class Section Percentage
Amy X B 95.0 %
Bernadette X D 92.7 %
Howard X A 90.23 %
Leanord X B 91.2 %
Penny X C 63.5 %
Raj X B 88.1 %
Sheldon X A 98.2 %
以上有问题。也就是说,它不会显示标题。要显示标题,您需要安装 PTable。一旦你这样做了上面的代码,就会产生:
Big Bang Theory
Student Name Class Section Percentage
Amy X B 95.0 %
Bernadette X D 92.7 %
Howard X A 90.23 %
Leanord X B 91.2 %
Penny X C 63.5 %
Raj X B 88.1 %
Sheldon X A 98.2 %
我有以下生成漂亮 table 的代码。我想做的是删除 vrules 或 hrules。我的代码没有做任何事情。你能告诉我为什么吗?只是为了确保,vrules 是垂直线
from prettytable import PrettyTable, FRAME, HEADER, NONE
PrettyTable().hrules = NONE
# x = PrettyTable()
# x.hrules = NONE
myTable = PrettyTable(["Student Name", "Class", "Section", "Percentage"])
myTable.title = 'Big Bang Theory'
# Add rows
myTable.add_row(["Leanord", "X", "B", "91.2 %"])
myTable.add_row(["Penny", "X", "C", "63.5 %"])
myTable.add_row(["Howard", "X", "A", "90.23 %"])
myTable.add_row(["Bernadette", "X", "D", "92.7 %"])
myTable.add_row(["Sheldon", "X", "A", "98.2 %"])
myTable.add_row(["Raj", "X", "B", "88.1 %"])
myTable.add_row(["Amy", "X", "B", "95.0 %"])
PrettyTable().vrules = NONE
print(myTable.get_string(sort_key=operator.itemgetter(1, 3), sortby="Section"))
它仍在生产相同的 table:
+---------------------------------------------+
| Big Bang Theory |
+--------------+-------+---------+------------+
| Student Name | Class | Section | Percentage |
+--------------+-------+---------+------------+
| Amy | X | B | 95.0 % |
| Bernadette | X | D | 92.7 % |
| Howard | X | A | 90.23 % |
| Leanord | X | B | 91.2 % |
| Penny | X | C | 63.5 % |
| Raj | X | B | 88.1 % |
| Sheldon | X | A | 98.2 % |
+--------------+-------+---------+------------+
根据 docs 你可以:
>>> myTable = PrettyTable()
>>> myTable.hrules, myTable.vrules = NONE, NONE
>>> myTable.title = 'Big Bang Theory' # this won't show, see below
>>> myTable.field_names = ["Student Name", "Class", "Section", "Percentage"]
>>> myTable.add_row(["Leanord", "X", "B", "91.2 %"])
>>> myTable.add_row(["Penny", "X", "C", "63.5 %"])
>>> myTable.add_row(["Howard", "X", "A", "90.23 %"])
>>> myTable.add_row(["Bernadette", "X", "D", "92.7 %"])
>>> myTable.add_row(["Sheldon", "X", "A", "98.2 %"])
>>> myTable.add_row(["Raj", "X", "B", "88.1 %"])
>>> myTable.add_row(["Amy", "X", "B", "95.0 %"])
>>> print(myTable.get_string(sort_key=operator.itemgetter(1, 3), sortby="Section"))
Student Name Class Section Percentage
Amy X B 95.0 %
Bernadette X D 92.7 %
Howard X A 90.23 %
Leanord X B 91.2 %
Penny X C 63.5 %
Raj X B 88.1 %
Sheldon X A 98.2 %
以上有问题。也就是说,它不会显示标题。要显示标题,您需要安装 PTable。一旦你这样做了上面的代码,就会产生:
Big Bang Theory
Student Name Class Section Percentage
Amy X B 95.0 %
Bernadette X D 92.7 %
Howard X A 90.23 %
Leanord X B 91.2 %
Penny X C 63.5 %
Raj X B 88.1 %
Sheldon X A 98.2 %