Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #29842 > unrolled thread
| Started by | jimbo1qaz <jimmyli1528@gmail.com> |
|---|---|
| First post | 2012-09-23 11:31 -0700 |
| Last post | 2012-09-23 20:11 +0100 |
| Articles | 8 — 5 participants |
Back to article view | Back to comp.lang.python
'str' object does not support item assignment jimbo1qaz <jimmyli1528@gmail.com> - 2012-09-23 11:31 -0700
Re: 'str' object does not support item assignment jimbo1qaz <jimmyli1528@gmail.com> - 2012-09-23 11:36 -0700
Re: 'str' object does not support item assignment Ian Kelly <ian.g.kelly@gmail.com> - 2012-09-23 12:45 -0600
Re: 'str' object does not support item assignment MRAB <python@mrabarnett.plus.com> - 2012-09-23 19:47 +0100
Re: 'str' object does not support item assignment jimbo1qaz <jimmyli1528@gmail.com> - 2012-09-23 11:55 -0700
Re: 'str' object does not support item assignment jimbo1qaz <jimmyli1528@gmail.com> - 2012-09-23 11:55 -0700
Re: 'str' object does not support item assignment Andrea Crotti <andrea.crotti.0@gmail.com> - 2012-09-23 19:48 +0100
Re: 'str' object does not support item assignment Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-09-23 20:11 +0100
| From | jimbo1qaz <jimmyli1528@gmail.com> |
|---|---|
| Date | 2012-09-23 11:31 -0700 |
| Subject | 'str' object does not support item assignment |
| Message-ID | <ec85c16b-086b-4b43-aba3-70a05f34cf69@googlegroups.com> |
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.
[toc] | [next] | [standalone]
| From | jimbo1qaz <jimmyli1528@gmail.com> |
|---|---|
| Date | 2012-09-23 11:36 -0700 |
| Message-ID | <0456eb94-237e-4376-9a49-ef8b0e93f82b@googlegroups.com> |
| In reply to | #29842 |
On Sunday, September 23, 2012 11:31:41 AM UTC-7, jimbo1qaz wrote: > 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. Yeah, it's a recursive function. Like it makes a difference.
[toc] | [prev] | [next] | [standalone]
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2012-09-23 12:45 -0600 |
| Message-ID | <mailman.1145.1348425941.27098.python-list@python.org> |
| In reply to | #29842 |
On Sun, Sep 23, 2012 at 12:31 PM, jimbo1qaz <jimmyli1528@gmail.com> wrote: > 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.
[toc] | [prev] | [next] | [standalone]
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2012-09-23 19:47 +0100 |
| Message-ID | <mailman.1147.1348426062.27098.python-list@python.org> |
| In reply to | #29842 |
On 2012-09-23 19:31, jimbo1qaz wrote: > 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.
[toc] | [prev] | [next] | [standalone]
| From | jimbo1qaz <jimmyli1528@gmail.com> |
|---|---|
| Date | 2012-09-23 11:55 -0700 |
| Message-ID | <76ce019e-6e3f-4732-a631-da5dabe20484@googlegroups.com> |
| In reply to | #29847 |
On Sunday, September 23, 2012 11:48:11 AM UTC-7, MRAB wrote: > On 2012-09-23 19:31, jimbo1qaz wrote: > > > 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. ya, I'm an idiot. I accidentally made a string instead of an array.
[toc] | [prev] | [next] | [standalone]
| From | jimbo1qaz <jimmyli1528@gmail.com> |
|---|---|
| Date | 2012-09-23 11:55 -0700 |
| Message-ID | <mailman.1149.1348426512.27098.python-list@python.org> |
| In reply to | #29847 |
On Sunday, September 23, 2012 11:48:11 AM UTC-7, MRAB wrote: > On 2012-09-23 19:31, jimbo1qaz wrote: > > > 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. ya, I'm an idiot. I accidentally made a string instead of an array.
[toc] | [prev] | [next] | [standalone]
| From | Andrea Crotti <andrea.crotti.0@gmail.com> |
|---|---|
| Date | 2012-09-23 19:48 +0100 |
| Message-ID | <mailman.1148.1348426187.27098.python-list@python.org> |
| In reply to | #29842 |
On 09/23/2012 07:31 PM, jimbo1qaz wrote: > 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..
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2012-09-23 20:11 +0100 |
| Message-ID | <mailman.1150.1348427460.27098.python-list@python.org> |
| In reply to | #29842 |
On 23/09/2012 19:31, jimbo1qaz wrote: > 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. -- Cheers. Mark Lawrence.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web