python - Transform Dictionary-Like Input to a Dictionary -
how transform dictionary input real dictionary can process?
when execute external command, get.
{'aaa': {'test_a': 0.11666666666667, 'test_b': 1, 'total_c': 0.11666666666667}, 'bbb': {'test_a': 32.883333333332999, 'test_b': 1, 'total_c': 0.11666666666667}, 'ccc': {'test_a': 11, 'test_b': 31, 'test'_c': 33}}
so, can see, above dictionary-format already. thinking of doing like.
#!/usr/bin/python import command result = commands.getoutput('<execute_external_command')
so 'result' becomes dictionary , can process dictionary.
from simplejson import loads result='{"name":"anton"}' dictionary=loads(result) print dictionary result="{'name':'anton'}" dictionary=loads(result.replace("'",'"')) print dictionary
Comments
Post a Comment