Answer the question
In order to leave comments, you need to log in
Why can't add int to list?
import pygame
pygame.init()
screen= pygame.display.set_mode((1000,600))
arr = []
for i in range(3):
arr.append(i)
print(i)
sprite = pygame.sprite.Group()
sprite.add(arr)
go = True
while go:
for event in pygame.event.get():
if event.type == pygame.QUIT:
go = False
0
0
1
2
Traceback (most recent call last):
File "D:\prog\Python\lib\site-packages\pygame\sprite.py", line 365, in add
self.add(*sprite)
TypeError: add() argument after * must be an iterable, not int
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\prog\Python\lib\site-packages\pygame\sprite.py", line 365, in add
self.add(*sprite)
File "D:\prog\Python\lib\site-packages\pygame\sprite.py", line 378, in add
sprite.add_internal(self)
AttributeError: 'int' object has no attribute 'add_internal'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\down\Drag-n-Drop.py", line 11, in <module>
sprite.add(arr)
File "D:\un\Python\lib\site-packages\pygame\sprite.py", line 376, in add
elif not self.has_internal(sprite):
File "D:\un\Python\lib\site-packages\pygame\sprite.py", line 326, in has_internal
return sprite in self.spritedict
TypeError: unhashable type: 'list'
Answer the question
In order to leave comments, you need to log in
Try this:
arr.append(str(i))
If you start swearing:
i = str(i)
arr.append(i)
And if you start swearing at this one, then I don't know at all...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question