[Tutor] Having trouble with " table % listTable.values() " line
Mihai Iacob
aymchaos at yahoo.com
Fri Nov 24 11:49:38 CET 2006
Hello,
This is my first post so if i make any kind of
mistakes take it easy on me :).
I don't know how to explain clearly what is the
problem but i'll try.
table = """
%s |%s |%s
-----------
%s |%s |%s
-----------
%s |%s |%s
"""
listTable is a dictionary.
listTable = {0 :'X', 1 :' ' , 2 :' ', 3 :'O', 4 :' ',
5 :' ', 6 :'O', 7 :' ', 8 :'X',}
I am trying to take the values from the dictionary
listTable.values() and print them in the table.
The problem is that listTable.values() returns a list
" ['X', ' ', ' ', 'O', ' ', ' ', 'O', ' ', 'X'] "
and python won't assign the values of the dictionary
in the table. " table % listTable.values() "
This error message appears:
Traceback (most recent call last):
File "<pyshell#81>", line 1, in <module>
table % listTable.values()
TypeError: not enough arguments for format string
So instead of the list " ['X', ' ', ' ', 'O', ' ', '
', 'O', ' ', 'X'] " which won't let me assign strings
in the table, i want to get ('X', ' ', ' ', 'O', ' ',
' ', 'O', ' ', 'X') from listTable.values()
I know i can make it work using:
table % (listTable[0],listTable[1],
listTable[2],listTable[3],listTable[4],
listTable[5],listTable[6],listTable[7],listTable[8])
but it's kinda long.
If somebody can tell me how to convert the []list into
() i'll make him a little shrine and worship him for 5
seconds :P
I'm trying to make a OXO game, so don't give me any
hints even if you spot mistakes (i hope i can make it
alone)
____________________________________________________________________________________
Do you Yahoo!?
Everyone is raving about the all-new Yahoo! Mail beta.
http://new.mail.yahoo.com
More information about the Tutor
mailing list