I'm trying to use the exec command in python to try to get a function to call on different dictionaries and functions as needs change without making my program bigger than it needs to be. Unfortunately I keep getting this error:

File "Game Files\Intro.py", line 214, in Anim
exec compile('%slegs = ImageTk.PhotoImage(Sprite%s["legs0"])'%(name,name), '<string>', 'exec') in Anim
TypeError: exec: arg 2 must be a dictionary or None

are the args 'compile' and 'in Anim', or is there something else I'm missing?