'str' object does not support item assignment

I

Ian Kelly

spots[y][x]=mark fails with a "'str' object does not support item assignment" error,even though:
a=[["a"]]
a[0][0]="b" and:
a=[["a"]]
a[0][0]=1000000
both work.
Spots is a nested list created as a copy of another list.

There's not enough information to go on here to even speculate what
might be causing the error, beyond "spots probably does not have the
structure you think it does". Please post the code that you're
actually running along with the full error traceback, and then maybe
we can help you out. Also try printing the value of spots just before
the assignment and see what it actually looks like.
 
M

MRAB

spots[y][x]=mark fails with a "'str' object does not support item assignment" error,even though:
a=[["a"]]
a[0][0]="b" and:
a=[["a"]]
a[0][0]=1000000
both work.
Spots is a nested list created as a copy of another list.
The error suggests that spots[y] is actually a string. Printing
repr(spots) and repr(spots[y]) should tell you whether it is.
 
A

Andrea Crotti

spots[y][x]=mark fails with a "'str' object does not support item assignment" error,even though:
a=[["a"]]
a[0][0]="b" and:
a=[["a"]]
a[0][0]=1000000
both work.
Spots is a nested list created as a copy of another list.

But
a = "a"
a[0] = 'c'
fails for the same reason, which is that strings in Python are immutable..
 
J

jimbo1qaz

spots[y][x]=mark fails with a "'str' object does not support item assignment" error,even though:
a=[["a"]]
a[0][0]="b"
a=[["a"]]
a[0][0]=1000000
both work.
Spots is a nested list created as a copy of another list.

The error suggests that spots[y] is actually a string. Printing

repr(spots) and repr(spots[y]) should tell you whether it is.

ya, I'm an idiot. I accidentally made a string instead of an array.
 
J

jimbo1qaz

spots[y][x]=mark fails with a "'str' object does not support item assignment" error,even though:
a=[["a"]]
a[0][0]="b"
a=[["a"]]
a[0][0]=1000000
both work.
Spots is a nested list created as a copy of another list.

The error suggests that spots[y] is actually a string. Printing

repr(spots) and repr(spots[y]) should tell you whether it is.

ya, I'm an idiot. I accidentally made a string instead of an array.
 
M

Mark Lawrence

spots[y][x]=mark fails with a "'str' object does not support item assignment" error,even though:
a=[["a"]]
a[0][0]="b" and:
a=[["a"]]
a[0][0]=1000000
both work.
Spots is a nested list created as a copy of another list.

Looks to me as if there are three options.
a) raise a bug report on the Python bug tracker at bugs.python.org.
b) fix your code.

As option b) is the likely route, the way forward is to put print
statements in your code so you can see what data you have *AND* what
type it is.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,008
Latest member
HaroldDark

Latest Threads

Top