Try using exec command. for example if you have a string temp_string = “print(‘hello world’)” and you want to execute this string as a command in python then you should use exec() function as
so in your case it should be exec(“pygame.Rect(50, 50, 100, 100)”)
I think it should work.
CLICK HERE to find out more related problems solutions.