我想知道如何静态初始化词典列表 - 是这样的:初始化字典的列表值
我本来像这样的列表:
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