奇怪的時間讓這個工作;記錄遞歸詞典
我有一個包含多臺機器信息的字典。根據參數選擇機器。
我想將選定的信息寫入日誌。但是我的遞歸嘗試似乎並沒有讓我走到需要去的地方。我得到鑰匙但價值失敗。
這是字典
CSTU_CFG = {'A07': {
'password': 'CastAIP', # default cast password(too lazy to use LDAP)
'host':'JSIPVWCASTD01',
'port':'2280', # Ports are assumed to be 2280 but can be any
'location': 'C:Users/WDI/Documents/CSTU/DMPRST', # use os.path to convert
'gzips': 'GZIPS', # location for zip files (Backup)
'schematype':{'local', 'central', 'mngt'},
'logintv': 30,
'version': '0.9'
},
'A01': {
'machine': 'A01',
'password': 'CastAIP', # default cast password(too lazy to use LDAP)
'host':'JSIPVWCASTD01',
'port':'2280', # Ports are assumed to be 2280 but can be any
'location': 'C:Users/WDI/Documents/CSTU/DMPRST', # use os.path to convert
'gzips': 'GZIPS', # location for zip files (Backup)
'schematype':{'local', 'central', 'mngt'},
'logintv': 30,
'version': '0.9'
},
'A02': {
'machine': 'A02',
'password': 'CastAIP', # default cast password(too lazy to use LDAP)
'host':'JSIPVWCASTD01',
'port':'2280', # Ports are assumed to be 2280 but can be any
'location': 'C:Users/WDI/Documents/CSTU/DMPRST', # use os.path to convert
'gzips': 'GZIPS', # location for zip files (Backup)
'schematype':{'local', 'central', 'mngt'},
'logintv': 30,
'version': '0.9'
}
}
logname = 'CSTU_'+timestr+'_'+ schemaname + '.CLOG'
logging.basicConfig(filename=logname,filemode='a',format='%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s', datefmt='%H:%M:%S',level=logging.DEBUG)
logging.debug("Starting CSTU_DUMP")
# print the CSTU_CFG file into the log
for key,value in CSTU_CFG:
logging.debug(key + " => " + value)
我顯然沒有得到上記錄點。我已經嘗試了一些建議的修復方法,但是我什麼也沒得到,或者出現了各種錯誤。我可以硬編碼它,但那不是意圖。 謝謝
謝謝你 - 這是有道理的和完美。日誌記錄需要一個字符串,所以我需要將鍵和值重新設置爲一個字符串,但效果很好。謝謝 ! (下次我會列出各種錯誤,再次感謝你) – WDickens
不客氣。請考慮將答案標記爲已接受和/或贊成。 –
尋找如何,現在。謝謝 – WDickens