如何在字符串中获取给定名称的变量的值?
为简单起见,这是我想要做的精简版:
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"
有什么办法吗?
繁星淼淼
侃侃尔雅
相关分类