我看到用户知道列的数量和名称的每个例子。如果我的字段名称在列表或字典中并且我不知道它们的数量怎么办?
我读到正确的代码是:
t = PrettyTable()
t.set_field_names("first","second","third")
但在我的情况下,名称位于名为columns的字典中:
columns = {column0: "first", column1: "second", column3: "third"}
我提醒我的列数是未知的。我尝试过:
for x in range(0,len(columns)):
target="column"+str(x)
t.set_field_names(columns[target])
或列表:
columns = ["first","second","third"]
t = PrettyTable()
t.set_field_names(columns)
但每次错误都是一样的:
File "time_based_blind.py", line 105, in <module>
t.set_field_names(columns)
File "/usr/lib/python2.7/dist-packages/prettytable.py", line 217, in __getattr__
raise AttributeError(name)
AttributeError: set_field_names
答案 0 :(得分:0)
PrettyTable没有属性set_field_names
你可能会改变它
columns = ["first","second","third"]
t = PrettyTable(columns)