Standard Python string formatting may suffice.

# assume that your data rows are tuples
template = "{0:8}|{1:10}|{2:15}|{3:7}|{4:10}" # column widths: 8, 10, 15, 7, 10
print template.format("CLASSID", "DEPT", "COURSE NUMBER", "AREA", "TITLE") # header
for rec in your_data_source: 
  print template.format(*rec)

Or

# assume that your data rows are dicts
template = "{CLASSID:8}|{DEPT:10}|{C_NUM:15}|{AREA:7}|{TITLE:10}" # same, but named
print template.format( # header
  CLASSID="CLASSID", DEPT="DEPT", C_NUM="COURSE NUMBER", 
  AREA="AREA", TITLE="TITLE"
) 
for rec in your_data_source: 
  print template.format(**rec)

Play with alignment, padding, and exact format specifiers to get best results.

Answer from 9000 on Stack Overflow
🌐
Python
docs.python.org › 3 › library › pprint.html
pprint — Data pretty printer
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. If the formatted structures include objects which are not fundamental Python types, the representation may not be loadable.
🌐
Code Beautify
codebeautify.org › python-formatter-beautifier
Python Formatter and Beautifier
Best Python Formatter will help to format, beautify, minify, compact Python code, string, text. Format, Save, Share
🌐
Real Python
realpython.com › python-pretty-print
Prettify Your Data Structures With Pretty Print in Python – Real Python
October 4, 2022 - The pprint module, Python's data pretty printer, is a useful part of the standard library. You can work with it for debugging data structures and increasing the readability of your output.
🌐
Textual
textual.textualize.io › widgets › pretty
Textual - Pretty
May 29, 2023 - The example below shows a pretty-formatted dict, but Pretty can display any Python object.
🌐
FavTutor
favtutor.com › blogs › pretty-print-dictionary-python
Pretty Print Dictionary in Python: pprint & json (with examples)
February 13, 2023 - The Python pprint (pretty-print) module provides a function to display complex data structures like dictionaries in a more readable format.
🌐
Rich
rich.readthedocs.io › en › latest › pretty.html
Pretty Printing — Rich 14.1.0 documentation
Run the following command to see an example of pretty printed output: python -m rich.pretty · Note how the output will change to fit within the terminal width. The pprint() method offers a few more arguments you can use to tweak how objects are pretty printed.
Top answer
1 of 5
69

Standard Python string formatting may suffice.

# assume that your data rows are tuples
template = "{0:8}|{1:10}|{2:15}|{3:7}|{4:10}" # column widths: 8, 10, 15, 7, 10
print template.format("CLASSID", "DEPT", "COURSE NUMBER", "AREA", "TITLE") # header
for rec in your_data_source: 
  print template.format(*rec)

Or

# assume that your data rows are dicts
template = "{CLASSID:8}|{DEPT:10}|{C_NUM:15}|{AREA:7}|{TITLE:10}" # same, but named
print template.format( # header
  CLASSID="CLASSID", DEPT="DEPT", C_NUM="COURSE NUMBER", 
  AREA="AREA", TITLE="TITLE"
) 
for rec in your_data_source: 
  print template.format(**rec)

Play with alignment, padding, and exact format specifiers to get best results.

2 of 5
11
class TablePrinter(object):
    "Print a list of dicts as a table"
    def __init__(self, fmt, sep=' ', ul=None):
        """        
        @param fmt: list of tuple(heading, key, width)
                        heading: str, column label
                        key: dictionary key to value to print
                        width: int, column width in chars
        @param sep: string, separation between columns
        @param ul: string, character to underline column label, or None for no underlining
        """
        super(TablePrinter,self).__init__()
        self.fmt   = str(sep).join('{lb}{0}:{1}{rb}'.format(key, width, lb='{', rb='}') for heading,key,width in fmt)
        self.head  = {key:heading for heading,key,width in fmt}
        self.ul    = {key:str(ul)*width for heading,key,width in fmt} if ul else None
        self.width = {key:width for heading,key,width in fmt}

    def row(self, data):
        return self.fmt.format(**{ k:str(data.get(k,''))[:w] for k,w in self.width.iteritems() })

    def __call__(self, dataList):
        _r = self.row
        res = [_r(data) for data in dataList]
        res.insert(0, _r(self.head))
        if self.ul:
            res.insert(1, _r(self.ul))
        return '\n'.join(res)

and in use:

data = [
    {'classid':'foo', 'dept':'bar', 'coursenum':'foo', 'area':'bar', 'title':'foo'},
    {'classid':'yoo', 'dept':'hat', 'coursenum':'yoo', 'area':'bar', 'title':'hat'},
    {'classid':'yoo'*9, 'dept':'hat'*9, 'coursenum':'yoo'*9, 'area':'bar'*9, 'title':'hathat'*9}
]

fmt = [
    ('ClassID',       'classid',   11),
    ('Dept',          'dept',       8),
    ('Course Number', 'coursenum', 20),
    ('Area',          'area',       8),
    ('Title',         'title',     30)
]

print( TablePrinter(fmt, ul='=')(data) )

produces

ClassID     Dept     Course Number        Area     Title                         
=========== ======== ==================== ======== ==============================
foo         bar      foo                  bar      foo                           
yoo         hat      yoo                  bar      hat                           
yooyooyooyo hathatha yooyooyooyooyooyooyo barbarba hathathathathathathathathathat
Find elsewhere
🌐
PyPI
pypi.org › project › pretty-python
pretty-python
May 24, 2023 - JavaScript is disabled in your browser. Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
🌐
Python
peps.python.org › pep-0813
PEP 813 – The Pretty Print Protocol | peps.python.org
March 4, 2026 - This PEP describes the “pretty print protocol”, a collection of changes proposed to make pretty printing more customizable and convenient.
🌐
GeeksforGeeks
geeksforgeeks.org › python › pprint-data-pretty-printer-python
pprint : Data pretty printer in Python - GeeksforGeeks
DSA Python · Data Science · NumPy ... (pretty print) is a built-in utility that formats complex data structures like dictionaries, lists, or JSON in a readable way with proper indentation and line breaks....
Published   January 9, 2026
🌐
Python
docs.python.org › id › 3.5 › library › pprint.html
8.11. pprint --- Data pretty printer — dokumentasi Python 3.5.10
Dokumen ini untuk versi lama Python yang tidak didukung lagi. Anda harus memutakhirkan, dan membaca Dokumentasi Python untuk rilis stabil saat ini. ... 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.
🌐
Visual Studio Code
code.visualstudio.com › docs › python › formatting
Formatting Python in VS Code
November 3, 2021 - Note: If you don't find your preferred formatter in the table above or in the Marketplace, you can add support for it via an extension. You can use the Python Extension Template to integrate new Python tools into VS Code.
🌐
Coderwall
coderwall.com › p › gmxnqg › pretty-printing-a-python-dictionary
Pretty Printing a Python dictionary (Example)
October 22, 2022 - Flatten a list of lists in one line in Python · #python · #json · Say Thanks · Respond · 201.5K · 15 · 64.1K · 0 · 59.22K · 12 · wyuenho · Alternatively. You can do this: import pprint · pprint.pprint(whateverdatastructureyouwant) over 1 year ago ·
🌐
PyPI
pypi.org › project › prettytable
prettytable · PyPI
A simple Python library for easily displaying tabular data in a visually appealing ASCII table format
      » pip install prettytable
    
Published   Nov 14, 2025
Version   3.17.0
🌐
seenode blog
seenode.com › blog › how-to-use-python-pretty-print-pprint
How to Use Python Pretty Print (pprint) for Cleaner Python Output | seenode blog
May 19, 2025 - It refers to “Pretty Print,” the native Python library that allows developers to customize their output experience with its different parameters and flags for a single class print (). This class effectively uses six parameters.
🌐
Reddit
reddit.com › r/learnpython › why pretty print?
r/learnpython on Reddit: Why Pretty Print?
October 7, 2020 -

Hi all

I'm trying to understand the usefulness of Pretty Print.

In automate the boring stuff it was used a few times earlier in the book to make things look 'prettier', it didn't really look much better to me but I assumed this was down to taste.

Now I just saw an actual use-case for it later in the book and it seems like a very convoluted method.

After importing pretty print, the format function can be used to convert a list to a string which makes it easier to write to a text doc and subsequently reimport (apparently). But you can just put 'str' in front of the list to achieve the same thing, so I fail to see the point.

Any ideas?

:\

🌐
Kanaries
docs.kanaries.net › topics › Python › pretty-print-dictionary-python
How to Use Pretty Print for Python Dictionaries – Kanaries
June 7, 2023 - Yet, their representation, particularly ... module slithers in to save the day. The pprint module, standing for "pretty print", aims to provide more readable and aesthetically pleasing representations of complex data structures, like dictionaries....
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-pretty-print-json
How to Pretty Print JSON in Python | DigitalOcean
September 16, 2025 - Learn how to pretty print JSON in Python using built-in tools like json.dumps() and pprint to improve readability and debug structured data efficiently.
🌐
Python
docs.python.org › 3 › library › json.html
json — JSON encoder and decoder
February 23, 2026 - indent (int | str | None) – If a positive integer or string, JSON array elements and object members will be pretty-printed with that indent level. A positive integer indents that many spaces per level; a string (such as "\t") is used to indent each level. If zero, negative, or "" (the empty string), only newlines are inserted.