TypeError: the type object is not indexable when indexing in a dictionary

I have several files that I need to download, so I use dictfor pruning. When I run, I get a TypeError: type object that is not indexable. Error. How can I make this work?

m1 = pygame.image.load(dict[1])
m2 = pygame.image.load(dict[2])
m3 = pygame.image.load(dict[3])
dict = {1: "walk1.png", 2: "walk2.png", 3: "walk3.png"}
playerxy = (375,130)
window.blit(m1, (playerxy))
+4
source share
1 answer

Python typically throws NameErrorif a variable is not defined:

>>> d[0]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'd' is not defined

However, you managed to stumble upon a name that already exists in Python.

Since dictthis is the name of a built-in type in Python , you see what seems like a strange error message, but in fact it is not.

dict - type. - Python. , type. , "type" ".

>>> type(dict)
<type 'type'>
>>> dict[0]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'type' object is not subscriptable

, dict, . .

>>> dict = {1:'a'}
>>> type(dict)
<class 'dict'>
>>> dict[1]
'a'

, . , :

d = {1: "walk1.png", 2: "walk2.png", 3: "walk3.png"}
m1 = pygame.image.load(d[1])
m2 = pygame.image.load(d[2])
m3 = pygame.image.load(d[3])
playerxy = (375,130)
window.blit(m1, (playerxy))
+11

All Articles