prettytable icon indicating copy to clipboard operation
prettytable copied to clipboard

Creating a PrettyTable inside a for.

Open GoogleCodeExporter opened this issue 9 years ago • 1 comments

Hello!

I'm trying to create a list inside a for and I'm doing this way:
________________________________________________________
for i in PSOE_data:
   if i[0] + i[1] + i[2] != 0:
        newList.append(i)

PSOE_list = PrettyTable(["Digital Chanel", "State", "Hour", "Minute", "Second"])
PSOE_list.align["Digital Chanel"] = "c" # Alinhamento pela esquerda
PSOE_list.padding_width = 1 # Espaçamento entre colunas (default)
PSOE_list.add_row([newList[i][3], newList[i][4], newList[i][0], newList[i][1], 
newList[i][2]])
print PSOE_list
________________________________________________________

But there is traceback that says:

    PSOE_list.add_row([newList[i][3], newList[i][4], newList[i][0], newList[i][1], newList[i][2]])
TypeError: list indices must be integers, not list


How can I deal with that?

Thank you!

Original issue reported on code.google.com by [email protected] on 19 Feb 2015 at 1:43

GoogleCodeExporter avatar Aug 22 '15 23:08 GoogleCodeExporter

There is no value assigned to the variable i in the second last line. What you 
want to do is replace the second last line with following:

for i in newList:
    PSOE_list.add_row([newList[i][3], newList[i][4], newList[i][0], newList[i][1], newList[i][2]])

So basically you add another loop.

Original comment by [email protected] on 13 May 2015 at 10:33

GoogleCodeExporter avatar Aug 22 '15 23:08 GoogleCodeExporter