I am learning how the classes work, but I have encountered a problem that had appeared to me on other occasions.
The question is that I want to have a class to which two parameters are passed: columns and rows. And that by calling a method inside the class, that table is automatically generated.
class Tables:
def __init__(self, rows, columns):
self.rows = rows
self.columns = columns
def generate_T(self):
table = BeautifulTable()
for i in range(self.rows):
table.rows.append([""])
print(table)
The table.rows.append
method requires that for each column this is inserted: "",
. I try this:
columns = "\"\","*self.columns
for i in range(self.rows):
table.rows.append([columns[:-1])
It does not work, since it is taken as a single text string, I have also tried to remove the comma from the function, but then some parentheses appear. Is there any method to fix this? Greetings and thanks
P.D: To be clear: table.rows.append (["", "", ""])