如何从类中的字符串列表中创建变量

时间:2018-10-18 18:55:24

标签: python

class WPawn():
    def __init__(self, x, y):
        self.x = x
        self.y = y
        self.image = pygame.transform.scale(pygame.image.load('wpawn.png'), (100,100))

class Game():
    def __init__(self):
        screen_width = 900
        screen_height = 900
        self.screen = pygame.display.set_mode((screen_width,screen_height))

        pygame.display.set_caption ("Chess Project")


        List = ['pawn1','pawn2','pawn3','pawn4','pawn5','pawn6','pawn7','pawn8']
        for x in range (len(List)):
            variable = (vars(self)[List[x]])
            self.variable = WPawn(50,650)

0 个答案:

没有答案