0

I have an array with 20 values, but value 16 is incorrent and must be replaced with the correct value. How can I do that?

texture[16] = 'sky13.jpg'

That code does not work for some reason. The error is "'tuple' object does not support item assignment"

2
  • Please recheck what exactly you're using. As the error suggests, you might be using a tuple instead of a list. Commented Jul 20, 2014 at 9:23
  • @Defi "The code does not work" deserves error trace sharing with us. Commented Jul 20, 2014 at 10:06

3 Answers 3

2

You're working with a tuple instead of a list. Convert it to a list first

texture = list(texture)
texture[16] = 'sky13.jpg
Sign up to request clarification or add additional context in comments.

Comments

1

check what texture is

type(texture)

if it is tuple then convert it to list

textute = list(texture)

in python simple way to talk tuple object is immutable list object

more about differences is here What's the difference between lists and tuples?

Comments

0

Tuples in Python are **inmutable**, which means that you can't change the value once you assign it!

You need to convert the tuple to a list:

listOfTextures = list(texture)

And then you will be able to change the values you want to.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.