jackmaney / prettytable

Automatically exported from code.google.com/p/prettytable
Other
0 stars 0 forks source link

Creating a PrettyTable inside a for. #66

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
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 dionatan...@gmail.com on 19 Feb 2015 at 1:43

GoogleCodeExporter commented 9 years ago
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 letsdore...@googlemail.com on 13 May 2015 at 10:33