Possible Duplicate:
How can I use a string with the same name of an object in Python to access the object itself?
我正在尝试根据匹配结果将名称更改为变量。。。在
inds_EUR = [whatever]
inds_AFR = [foo]
inds_ASN = [other]
pop=inds_EUR ##imagine this is the case
for pp in ('EUR', 'AFR', 'ASN'):
if pp in pop:
paap='inds_'+str(pp)
break
foos=eval(paap)
我要做的是将“foos”设置为要传递给这个表达式的列表
^{pr2}$它可以工作,但不知道使用eval()表达式是否危险,这里使用vars()可能是这样 我做得对吗?在
提前谢谢你
佩西
使用字典:
相关问题 更多 >
编程相关推荐