FAQ
pretty self-explanatory, here's what I put in:

while stat == 0 :
pgrid#ignore, A pre-defined function
print "what cell do you want?"
varcc = raw_input
grid[varc] = 'O'

And here's what I get back:

Traceback (most recent call last):
File "C:\py_prog\Tic Tac Toe.py", line 27, in <module>
grid[varc] = 'O'
TypeError: list indices must be integers

Please don't tell me that "list indices must be integers" because I know
that, Why can't I put a varible thats an integer instead?



-- Posted on news://freenews.netfront.net - Complaints to news at netfront.net --

Search Discussions

  • Christian Heimes at Sep 5, 2008 at 11:54 pm

    Lanny wrote:
    Please don't tell me that "list indices must be integers" because I know
    that, Why can't I put a varible thats an integer instead?

    raw_input() always returns a string. You have to convert the string into
    an integer using int().

    Christian
  • BearophileHUGS at Sep 6, 2008 at 12:00 am

    Lanny:
    ...
    varcc = raw_input
    grid[varc] = 'O'
    ...
    Why can't I put a varible thats an integer instead?
    'varcc' and 'varc' are different names.

    'raw_input' isn't a function call, you may want to turn that into a
    function call.

    varc isn't an integer, you may have to convert it to integer first,
    using int(), because Python lists aren't like Lua ones, they are
    represented with a sequence of cells, and an integer number is used to
    denote what cells you want. Note that the cell must already exists
    before accessing its contents.

    Maybe you want to use an associative array instead, named 'dict' in
    Python, that allows you freedom in the type of the keys and allows you
    to create cells on the fly.

    Surely my answer isn't enough to solve your problems, but it may give
    you a starting point.

    Bye,
    bearophile
  • Lanny at Sep 6, 2008 at 9:43 pm

    Lanny:
    ...
    varcc = raw_input
    grid[varc] = 'O'
    ...
    Why can't I put a varible thats an integer instead?
    'varcc' and 'varc' are different names.

    'raw_input' isn't a function call, you may want to turn that into a
    function call.

    varc isn't an integer, you may have to convert it to integer first,
    using int(), because Python lists aren't like Lua ones, they are
    represented with a sequence of cells, and an integer number is used to
    denote what cells you want. Note that the cell must already exists
    before accessing its contents.

    Maybe you want to use an associative array instead, named 'dict' in
    Python, that allows you freedom in the type of the keys and allows you
    to create cells on the fly.

    Surely my answer isn't enough to solve your problems, but it may give
    you a starting point.

    Bye,
    bearophile
    Thanks, this was very usefull



    -- Posted on news://freenews.netfront.net - Complaints to news at netfront.net --

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedSep 5, '08 at 11:54p
activeSep 6, '08 at 9:43p
posts4
users3
websitepython.org

People

Translate

site design / logo © 2022 Grokbase