473,394 Members | 1,746 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

indices question

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 ne**@netfront.net --
Sep 5 '08 #1
3 1024
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

Sep 5 '08 #2
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
Sep 6 '08 #3
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 ne**@netfront.net --
Sep 6 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: dan | last post by:
I was recently surprised, and quite shocked in fact, to find that Python treats negative indices into sequence types as if they were mod(length-of-sequence), at least up to -len(seq). This fact...
6
by: SnuSnu | last post by:
Okay - here's a (probably) really easy question: I can't do the following, so what's the best way to handle this case of wanting to delete within a loop? x = deletion_list = for i in...
5
by: Ross MacGregor | last post by:
I have a very simple yet complicated problem. I want to generate a random list of indices (int's) for a container. Let's say I have a container with 10 items and I want a list of 3 random...
7
by: Bart Torbert | last post by:
Hello, I am starting to examine using SQLServer instead of Oracle. I went through the SQLServer import utility to copy tables from Oracle into SQLServer. I then checked the size of the...
9
by: Richard A. DeVenezia | last post by:
Can someone explain why JavaScript arrays are not allowed to have objects as indices ? Would solve many a hashtable lookup problems.... -- Richard A. DeVenezia
9
by: Randell D. | last post by:
Folks, I can program fairly comfortably in PHP and can, for the most part using these skills and others that I've picked up over the years manage to read/understand most code in Javascript... so...
3
by: David Mathog | last post by:
This one is driving me slightly batty. The code in question is buried deep in somebody else's massive package but it boils down to this, two pointers are declared, the first is: char **resname...
3
by: GavinCrooks | last post by:
The indices method of slice doesn't seem to work quite how I would expect when reversing a sequence. For example : '43210' '43210' So a slice with a negative step (and nothing else) reverses...
2
by: smichr | last post by:
It seems to me that the indices() method for slices is could be improved. Right now it gives back concrete indices for a range of length n. That is, it does not return any None values. Using an...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.