'for' loop in python, error: unsubscriptable object

Brad Hards bhards at bigpond.net.au
Mon Nov 18 05:25:47 EST 2002


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Mon, 18 Nov 2002 20:55, george wrote:
> Hello:
>    I am new to python.
/AOL.

>    for max in range[CLA, RBW, BAG, MRB, NOG]:
What are you trying to do here? Do you just want to iterate through the 
values?

Let's look at the on-line help for range():
range(...)
    range([start,] stop[, step]) -> list of integers

    Return a list containing an arithmetic progression of integers.
    range(i, j) returns [i, i+1, i+2, ..., j-1]; start (!) defaults to 0.
    When step is given, it specifies the increment (or decrement).
    For example, range(4) returns [0, 1, 2, 3].  The end point is omitted!
    These are exactly the valid indices for a list of 4 elements.

I can't see what possible values you could put into the five arguments to the 
heat() function that would make sense as arguments to range().

Perhaps you just want to do 
for max in [CLA, RBW, BAG, MRB, NOG]:
instead?

> BUT WHEN I EXECUTE IT ,
> THE PROGRAM SAYS "for max in range[CLA, RBW, BAG, MRB, NOG]:
>                   type error: unsubcriptable object"
Please don't shout (which is the what user uppercase means on the net).

Also, can you show how you are calling heat()?

Brad
- -- 
http://linux.conf.au. 22-25Jan2003. Perth, Aust. I'm registered. Are you?
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE92MArW6pHgIdAuOMRAoxOAJsFSr8AMAfEYWy7sF3HG47iIIfDCgCgjAno
1WcCFa4XL2YU2Rlx+aS3UhQ=
=3YTl
-----END PGP SIGNATURE-----





More information about the Python-list mailing list