我想知道如何靜態初始化詞典列表 - 是這樣的:初始化字典的列表值
我本來像這樣的列表:
consumers = ['aserver.foo.com','anotherserver.foo.com',
'thirdserver.foo.com','lastserver.foo.com']
但我想有一個結構,我可以解決這樣的:
consumers = [
'aserver'{
'hostname'='aserver.foo.com',
'binddn'=masterbinddn,
'bindpw'=masterbindpw
},
'anotherserver'{
'hostname'='anotherserver.foo.com',
'binddn'=masterbinddn,
'bindpw'=masterbindpw
},
'athirdserver'{
'hostname'='athirdserver.foo.com',
'binddn'=targetbinddn,
'bindpw'=targetbindpw
},
'lastserver'{
'hostname'='lastserver.foo.com',
'binddn'=targetbinddn,
'bindpw'=targetbindpw
}
]
的想法是,我可以這樣做:
for server in consumers:
do_something_to_server(server['hostname'], server['binddn'], server['bindpw'])
我在吠叫錯誤的樹,還是錯過了一些基本的東西?
所以你爲什麼認爲你不能這樣做? – 2012-03-02 16:01:40