Theory and Practice
About Archives Categories Tags Authors 中文 ไทย

[Python] Pretty Print Variable (Dictionary, List, Object, Array)

March 09, 2013
Edit on Github

The easiest way is through json module included in Python:

print(json.dumps(obj, sort_keys=True, indent=4, separators=(',', ': ')))

where obj is your variable, could be dictionary (equivalent to object in JavaScript) or list (equivalent to array in JavaScript).


Author: Siong-Ui Te
∈ Category: Python
∑ Tags: pretty print , Python , JSON
Powered by Github Pages, Pelican, pyScss.