wx position of items in list

Cliff Wells clifford.wells at comcast.net
Mon Oct 25 05:39:53 CEST 2004

On Sun, 2004-10-24 at 19:13 +0100, M. Clift wrote:

>  I am getting the following error  regardless of whether I
> use a list or string,  'unsupported operand type(s) for //: 'str' and
> 'int''.  

That's because you're trying to divide i (a string) by an integer.

>         for i in text:
>             shape.pos = (145, 170 + (i//2)*100)
>             self.shapes.append(shape)

Try this instead:

for i in range(len(text)):
    shape.pos = (145, 170 + (i//2)*100)

For future reference, try adding print statements when you get errors
like this so you can verify that you are doing what you think you are.
I'm assuming that you know you can't divide a string by an integer, so
my guess is that for some reason you thought that 'for i in text' would
give you a list of integers.  A quick 'print i' after the for statement
would have told you otherwise (as would have the Python tutorial had you
bothered to read it).


Cliff Wells <clifford.wells at comcast.net>

More information about the Python-list mailing list