漂亮表: "if len(self._rows) in (0, len(column)): AttributeError: 'str' object has no attribute '_row



我正在尝试使用文档制作一个基本表。这是我版本的代码:

from prettytable import *
table = PrettyTable
table.add_column("", "Pokemon Name", ["Pikachu", "Squirtle", "Charmander"]) 
table.add_column("", "Type", ["Electric Type", "Water Type", "Fire Type"])
print(table)

我尝试过删除和重新安装prettytable,但问题仍然存在。

if len(self._rows) in (0, len(column)):
AttributeError: 'str' object has no attribute '_rows'

我还能做些什么来解决这个问题吗?

在python中实例化对象的正确方法是table = PrettyTable()

然后更改以下代码:

table.add_column("Pokemon Name", ["Pikachu", "Squirtle", "Charmander"]) 
table.add_column("Type", ["Electric Type", "Water Type", "Fire Type"])
print(table)

错误是由于您将self作为"" 传递

最新更新