0
我需要在dict對象中獲得「結果」,我正在循環並獲取以下格式的鍵和值,這些格式是我在變量「opp」中定義的。使用python存儲一組格式化的自定義字符串到字典
我需要的是我想存儲數據(即從opp)到字典。我怎樣才能做到這一點?
這裏是我的代碼:
for service, svc_limits in result.items():
for limit_name, limit in svc_limits.items():
for warn in limit.get_warnings():
opp = ("'{service}/'{limit_name}'': '[{u}]'".format(
service=service,limit_name=limit_name,u=str(warn))
)
我的樣本輸出:
{"contact": {"permanentnumber":"sample123","tempnum":"jki345"}}
從這一點,我得到了輸出
contact/permanentnumber:sample123
contact/tempnum:jki345
,並把它作爲一個單獨的字符串數據類型。
我需要以字典格式存儲這組字符串,使用轉儲寫入YAML文件,但它不工作。只有一組值被寫入文件。我需要將這兩個值存儲在新文件中。
opp = ("'{service}/'{limit_name}'': '[{u}]'".format(
service=service,
limit_name=limit_name,
u=str(warn)
)
)
samp = {opp}
它只返回我設置dtatype,但我需要的是字典。
set(["'Contact/'permanentnumber'': '[4]'"]) <type 'set'>
set(["'Contact/'temporarynum' ': '[4]'"]) <type 'set'>
我該如何處理?
謝謝安東... – user4223185