小编A.L*_*Lex的帖子

Python:从字典中运行代码

字典是从配置文件生成的:

    dict_1 = {
            'type1' : 'function1()',
            'type2' : 'function2()',
            'type3' : 'function3()'
        }
Run Code Online (Sandbox Code Playgroud)

变量x包含此字典中的任何键.我试着按如下方式调用函数:

dict_1[x]
Run Code Online (Sandbox Code Playgroud)

有没有人知道运行此语句的exec函数的替代方法?

python dictionary

2
推荐指数
1
解决办法
161
查看次数

标签 统计

dictionary ×1

python ×1