I was wondering if there was a way to generate class attributes by looping over the arguments of the init method without explicitly referring to a list containing all the arguments of the init method?
In the example below could I loop over hp, image, speed, x, y to create the self arguments ?
class Character(pygame.sprite.Sprite):
def __init__(self, hp, image, speed, x, y):
# Call the parent class (Sprite) constructor
super(Character, self).__init__()
self.image = image
self.rect = self.image.get_rect().move(x, y) #initial placement
self.speed = speed
self.hp = hp
For example with a loop that would look like that:
class Character(pygame.sprite.Sprite):
def __init__(self, hp, image, speed, x, y):
# Call the parent class (Sprite) constructor
super(Character, self).__init__()
for arg in arguments:
self.arg = arg
I am not quite sure how to get the "arguments" to refer to hp, image, speed, x and y ? Or am I stuck with using a list like below ?
class Character(pygame.sprite.Sprite):
def __init__(self, hp, image, speed, x, y):
# Call the parent class (Sprite) constructor
super(Character, self).__init__()
for arg in [self, hp, image, speed, x, y]:
self.arg = arg