If a function is nested in another function, you're not allowed to use unqualified exec
in either of the two functions. Unqualified in this case means "without in
". An explanation of why this limitation exists can be found here.
In your code you don't really need exec
. To set and get global variables by name, you can just use globals()[name]
, but you don't even need global variables either. You can just define cache
and rankings
as local variables in mu_cache
and then access them in wrap
.
Another error in your code is that you use global rankings
in delete_smallest
. This will cause an error message about there being no global variable named rankings because rankings
is a local variable in the wrap
function, not a global variable. If you just remove that line, the error will disappear and you will be correctly able to access the rankings
variable.