indices question

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Sat Sep 6 02:00:04 CEST 2008


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



More information about the Python-list mailing list