2 回答
TA贡献1797条经验 获得超4个赞
measurements = {'tg': [8.184e+16, 8.345e+16, 8.045e+16, 8.520e+16, 8.322e+16, 7.622e+16, 4.305e+16, 2.203e+16]}
def f():
for key,val in measurements.items():
exec('{} = {}'.format(key, val))
print (tg)
local = locals()
for key in measurements.keys():
print 'Key: ', key, ', Value: ', local[key]
f()
蟒蛇3:
measurements = {'tg': [8.184e+16, 8.345e+16, 8.045e+16, 8.520e+16, 8.322e+16, 7.622e+16, 4.305e+16, 2.203e+16]}
def f():
for key,val in measurements.items():
exec('global {};{} = {}'.format(key, key, val))
print ('tg: ', tg)
vars = globals()
for key in measurements.keys():
print ('Key: ', key, ', Value: ', vars[key])
f()
输出:
[8.184e+16, 8.345e+16, 8.045e+16, 8.52e+16, 8.322e+16, 7.622e+16, 4.305e+16, 2.203e+16]
Key: tg , Value: [8.184e+16, 8.345e+16, 8.045e+16, 8.52e+16, 8.322e+16, 7.622e+16, 4.305e+16, 2.203e+16]
添加回答
举报