python-3.xprettytable

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


I'm trying to make a basic table by using the documentation. This is my version of the code:

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)

I have tried removing, and reinstalling prettytable, but the problem still persists.

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

Is there anything else I can do to resolve this issue?


Solution

  • The proper way to instantiate an object in python is table = PrettyTable()

    Then change your code for the following:

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

    The error was coming from the fact that you where passing self as ""