Pro-grammer Pro-grammer - 1 year ago 167
Python Question

How to fix a : TypeError 'tuple' object does not support item assignment

The following fragment of code from this tutorial:

for badguy in badguys:
if badguy[0]<-64:
for badguy in badguys:
screen.blit(badguyimg, badguy)

is giving me a :

TypeError: 'tuple' object does not support item assignment

I understand that this could be becuse
is a tuple. This means it is immutable(you can not change its values) Ive tried the following:

t= list(badguy)
t[0]= t[0]-7

I converted the tuple to a list so we can minus 7. But in the game nothing happens.

Does any one know what I could do?


Answer Source

Change this


into this

badguy = list(badguy)
badguy = tuple(badguy)

Alternatively, if you can leave badguy as a list, then don't even use tuples and you'll be fine with your current code (with the added change of using lists instead of tuples)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download