473,386 Members | 1,606 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,386 software developers and data experts.

problem in reading indices

Hi all

I'm becoming mad, because I can't see what's wrong:

I am constructing a GUI, to plot some data.
so let's have a look of what's wrong:

in my code I have a variable named choice[i].current which is the
current selection of the i-th Listbox object. it is a tuple, with one
element.

so when I write

print type(i),type(choice[i].current)
I have: int and tuple

print type(i),type(choice[i].current[0])
I have: int and str

print type(i),type(int(choice[i].current[0]))
I have: int and int

so when I call another array with these indices
ArrayWithData[i,int(choice[i].current[0])]

I have the following error: TypeError: list indices must be integers

so I tried an intermediate value, because sometimes, the oneliner code
doesn't work, so with an intermediate passage:
value=int(choice[i].current[0])
ArrayWithData[i,value]

I have the same error

and I don't understand why. What's wrong?
May anyone have an idea?
Xavier

pm:
and print type(ArrayWithData), ArrayWithData gives me
<type 'list'[array([ 2.01, 5.01]),...]

Dec 13 '07 #1
2 1066
Xavier Barthelemy a écrit :
Hi all

I'm becoming mad, because I can't see what's wrong:

I am constructing a GUI, to plot some data.
so let's have a look of what's wrong:

in my code I have a variable named choice[i].current which is the
current selection of the i-th Listbox object. it is a tuple, with one
element.

so when I write

print type(i),type(choice[i].current)
I have: int and tuple

print type(i),type(choice[i].current[0])
I have: int and str

print type(i),type(int(choice[i].current[0]))
I have: int and int

so when I call another array with these indices
ArrayWithData[i,int(choice[i].current[0])]

I have the following error: TypeError: list indices must be integers
the syntax for list subscripting is:

thelist[index]

not:

thelist[index,index]
If the item at thelist[index] is itself an object that supports
subscripting and you want to subscript it to (which seems to be the case
here), the syntax is:

thelist[index][subindex]

IOW, try with:

ArrayWithData[i][int(choice[i].current[0])]
so I tried an intermediate value, because sometimes, the oneliner code
doesn't work,
if you're sure that choice[i].current[0] exists and can be passed to the
int type, there's no reason for the oneliner to behave differently.

HTH
Dec 13 '07 #2
Xavier Barthelemy wrote:
so when I call another array with these indices
ArrayWithData[i,int(choice[i].current[0])]
You don't "call" "arrays" "with indices". You are indexing the list
ArrayWithData using the index "i,int(blah)" which is invalid.
Indices must be integers, not comma seperated values.
so I tried an intermediate value, because sometimes, the oneliner
code doesn't work, so with an intermediate passage:
value=int(choice[i].current[0])
ArrayWithData[i,value]

I have the same error

and I don't understand why. What's wrong?
May anyone have an idea?
I'm afraid not! You didn't specify at all what you'd like to achieve
(just "it doesn't work! why?), and clairvoyance isn't as easy as it
looks.

If you want to slice, don't use Perl syntax. Python uses a colon for
index separation to eliminate ambiguities.

some_elements = my_list[3:10]

Regards,
Björn
--
BOFH excuse #343:

The ATM board has run out of 10 pound notes. We are having a whip
round to refill it, care to contribute ?

Dec 13 '07 #3

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

Similar topics

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...
2
by: Alexander Schmidt | last post by:
Hi, I am not very familiar with C++ programming, so before I do a dirty hack I ask for a more elegant solution (but only the usage of STL is allowed, no special libs). So I need to read a file...
8
by: laniik | last post by:
Hi. I have a problem using STL's built in sort that seems impossible to get around. if i have: -------------------------------- struct object { int val; }
8
by: Klaus Schneider | last post by:
Hi all! I'm having trouble with a template function with variable arguments when I parse an enum type as variable argument. Example: template <class T> bool test(int num, ...) { va_list ap;...
18
by: Joe Blow | last post by:
Can anybody see a problem with this? Am I being stupid? if (!isset($_REQUEST) || "" == $_REQUEST) { throw new Exception("need query"); } else { echo "<p>Search words: $_REQUEST"; }
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...
9
by: Jerim79 | last post by:
Here it is: <?php if($_SERVER=='POST'){ $Number=$_POST; $Email=$_POST; $Number2=0; $error=0;
2
by: mkvenkit.vc | last post by:
Hello, I hope this is the right place to post a question on Boost. If not, please let me know where I can post this message and I will do so. I am having a strange problem with std::string as...
43
by: John | last post by:
Hi This .net is driving me crazy!! In VB6 I had a type which contained a couple of multi-dimentional arrays which i used to create and read records: Type AAA : Array1(10,10,2) as Integer
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.