为了简单起见,这是我想要做的事情的一个精简版本:
def foo(a):
# I want to print the value of the variable
# the name of which is contained in a
我知道如何在 PHP 中做到这一点:
function foo($a) {
echo $$a;
}
global $string = "blah"; // might not need to be global but that's irrelevant
foo("string"); // prints "blah"
有什么办法吗?