Python-如何在字符串中获取给定变量名称的值?
发布于 2021-02-02 23:15:41
为简单起见,这是我要执行的操作的简化版本:
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"
有什么办法吗?
关注者
0
被浏览
105
1 个回答