- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to Pretty print Python dictionary from command line?
You can pretty print a dict in python using the pprint library. The pprint module provides a capability to “pretty-print” arbitrary Python data structures in a form which can be used as input to the interpreter. You can use it as follows
Example
a = { 'bar': 22, 'foo': 45 } pprint.pprint(a, width=10)
Output
This will give the output:
{'bar': 22, 'foo': 45}
As you can see that even this can be unreadable. You can use the json module to actually print it better. For example,
Example
import json a = { 'bar': 22, 'foo': 45 } print(json.dumps(a, indent=4))
Output
This will give the output:
{ "bar": 22, "foo": 45 }
- Related Articles
- How to run Python functions from command line?
- How to call Python module from command line?
- How to pretty print json using javascript?
- How to read a file from command line using Python?
- How to write into a file from command line using Python?
- How to run TestNG from command line?
- How to upgrade MySQL server from command line?
- How to print Python dictionary into JSON format?
- How to do Python math at command line?
- How to add command line arguments in Python?
- How to repair MySQL tables from the command line?
- How can we return to windows command shell from MySQL command line tool?
- How to run Python functions in Eclipse command line?
- How to execute Python multi-line statements in the one-line at command-line?
- Connect to MySQL database from command line

Advertisements