A simple Python implementation to pretty print dictionaries
Supports
- Python 2
- Python 3
- Set column width
- Support for multi-line dictionaries
- Sort by column
- neat-dictionary-fixed-column-width.py
- neat_printer
- neat_writer
- neat-dictionary-custom-column-width.py
- neat_printer
- neat_writer
- neat-multiline-custom-width.py
- multiline_printer
- multiline_writer
- neat-multiline-fixed-width.py
- multiline_printer
- multiline_writer
- neat-sorted-custom-width.py
- neat_printer
- neat_writer
neat_printer(dictionary_variable, [list_of_titles], column_width)
dictionary = {egg: ["Qty. 1", 1],
bread: ["Qty. 2", 2]}
neat_printer(dictionary,["Item","Quantity","Price"],10)
OUTPUT
Item Quantity Price
egg Qty. 1 1
bread Qty. 2 2
neat_printer(dictionary,["Item","Quantity","Price"],20)
OUTPUT when width == 20:
Item Quantity Price
egg Qty. 1 1
bread Qty. 2 2
neat_writer(dictionary_variable, [list_of_titles], column_width, output_file)
dictionary = {egg: ["Qty. 1", 1],
bread: ["Qty. 2", 2]}
file = open("neat_writing.txt", "w")
neat_writer(dictionary, ["Item","Quantity","Price"], 10, file)
OUTPUT FILE:
Item Quantity Price
egg Qty. 1 1
bread Qty. 2 2
neat_printer(dictionary_variable, [list_of_titles], [list_of_column_width])
dictionary = {egg: ["Qty. 1", 1],
bread: ["Qty. 2", 2]}
neat_printer(dictionary,["Item","Quantity","Price"],[6,10,10])
OUTPUT
Item Quantity Price
egg Qty. 1 1
bread Qty. 2 2
neat_writer(dictionary_variable, [list_of_titles], [list_of_column_width], file)
dictionary = {egg: ["Qty. 1", 1],
bread: ["Qty. 2", 2]}
file = open("neat_writing.txt", "w")
neat_writer(dictionary, ["Item","Quantity","Price"], [6,10,10], file)
OUTPUT FILE:
Item Quantity Price
egg Qty. 1 1
bread Qty. 2 2
multiline_printer(dictionary_variable, [list_of_titles], [list_of_column_width])
dictionary = {"egg":[["Qty. 1",1], ["Qty. 2",2], ["Qty. 4",3]],
"bread":[["Qty. 2",2], ["Qty. 3",3]]}
multiline_printer(dictionary,["Item","Quantity","Price"],[6,10,10])
OUTPUT
Item Quantity Price
egg Qty. 1 1
egg Qty. 2 2
egg Qty. 4 3
bread Qty. 2 2
bread Qty. 3 3
multiline_writer(dictionary_variable, [list_of_titles], [list_of_column_width], output_file)
dictionary = {"egg":[["Qty. 1",1], ["Qty. 2",2], ["Qty. 4",3]],
"bread":[["Qty. 2",2], ["Qty. 3",3]]}
file = open("multiline_writing.txt", "w")
multiline_writer(dictionary,["Item","Quantity","Price"],[6,10,10],file)
OUTPUT FILE
Item Quantity Price
egg Qty. 1 1
egg Qty. 2 2
egg Qty. 4 3
bread Qty. 2 2
bread Qty. 3 3
multiline_printer(dictionary_variable, [list_of_titles], column_width)
dictionary = {"egg":[["Qty. 1",1], ["Qty. 2",2], ["Qty. 4",3]],
"bread":[["Qty. 2",2], ["Qty. 3",3]]}
multiline_printer(dictionary,["Item","Quantity","Price"],10)
OUTPUT
Item Quantity Price
egg Qty. 1 1
egg Qty. 2 2
egg Qty. 4 3
bread Qty. 2 2
bread Qty. 3 3
multiline_writer(dictionary_variable, [list_of_titles], column_width, output_file)
dictionary = {"egg":[["Qty. 1",1], ["Qty. 2",2], ["Qty. 4",3]],
"bread":[["Qty. 2",2], ["Qty. 3",3]]}
file = open("multiline_writing.txt", "w")
multiline_writer(dictionary,["Item","Quantity","Price"],10,file)
OUTPUT
Item Quantity Price
egg Qty. 1 1
egg Qty. 2 2
egg Qty. 4 3
bread Qty. 2 2
bread Qty. 3 3
neat_printer(dictionary_variable, [list_of_titles], [list_of_column_width], title_to_sort_by)
dictionary = {egg: ["Qty. 1", 1],
bread: ["Qty. 2", 2]}
neat_printer(dictionary,["Item","Quantity","Price"],[6,10,10],"Item")
OUTPUT
Item Quantity Price
bread Qty. 2 2
egg Qty. 1 1
neat_printer(dictionary,["Item","Quantity","Price"],[6,10,10],"Price")
OUTPUT
Item Quantity Price
egg Qty. 1 1
bread Qty. 2 2
neat_writer(dictionary_variable, [list_of_titles], [list_of_column_width], title_to_sort_by)
dictionary = {egg: ["Qty. 1", 1],
bread: ["Qty. 2", 2]}
file = open("neat_writer.txt", "w")
neat_writer(dictionary,["Item","Quantity","Price"],[6,10,10],file,"Item")
OUTPUT FILE
Item Quantity Price
bread Qty. 2 2
egg Qty. 1 1
file = open("neat_writer.txt", "w")
neat_printer(dictionary,["Item","Quantity","Price"],[6,10,10],file,"Price")
OUTPUT FILE
Item Quantity Price
egg Qty. 1 1
bread Qty. 2 2