擅长:python、mysql、java
<pre><code>def extract_nodes():
to_return_dict = dict()
for i in json.load(open('/home/ubuntu/slcakbot_openNMS/CLEAR/out.txt'))["node"]:
try:
socket.inet_aton(i["label"])
to_return_dict[i['id']] = i['label']
print(i["label"])
print(i["id"])
#return { 'ip': i["label"], 'id': i["id"]} # i need to return these values
except Exception as e:
pass
return to_return_dict
</code></pre>
<p>这应该可以。。。。让我知道它是否有效!你知道吗</p>
<p>编辑:</p>
<p>至于如何使用:</p>
<pre><code>id_label_dict = extract_nodes()
print(id_label_dict['ip']) # should print the label associated with 'ip'
</code></pre>