Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pprint python

# pprint (aka prettyprint) is a function that allow to print objects in a clearer way
# Fist you need to import the pprint module
import pprint
# then you can create a printer whith whatever arguments you need
my_printer = pprint.PrettyPrinter(width=20)
# default arguments are : indent=1, width=80, depth=None, stream=None, *, compact=False, sort_dicts=True

# let's take this list as an exemple:
list1 = [[0,1,2,3,4],[1,2,3,4,5],[2,3,4,5,6],[3,4,5,6,7]]

print(list1) # will print [[0,1,2,3,4],[1,2,3,4,5],[2,3,4,5,6],[3,4,5,6,7]]
my_printer.pprint(list1) # will print:
# [[0, 1, 2, 3, 4],
#  [1, 2, 3, 4, 5],
#  [2, 3, 4, 5, 6],
#  [3, 4, 5, 6, 7]]

# You can also formant text whith pprint
output = my_printer.pformat(list1)
# output will be:
"""[[0, 1, 2, 3, 4],
 [1, 2, 3, 4, 5],
 [2, 3, 4, 5, 6],
 [3, 4, 5, 6, 7]]"""
Comment

PREVIOUS NEXT
Code Example
Python :: for e in p.event.get(): pygame.error: video system not initialized 
Python :: yesterday in python 
Python :: get current week python 
Python :: python import text file 
Python :: remove x label matplotlib 
Python :: types of all columns pandas 
Python :: href in selenium 
Python :: colab tqdm import 
Python :: required validator python WTForms 
Python :: python hour from datetime 
Python :: requirements file generate django 
Python :: acess nvidia from docker compose 
Python :: how to get the angle of mouse from the center formulae 
Python :: save dataframe to csv without index 
Python :: python how to unnest a nested list 
Python :: install auto-py-to-exe 
Python :: how to set default python version in macos 
Python :: pandas read csv without header 
Python :: zeller year 
Python :: Find the second lowest grade of any student(s) from the given names and grades of each student using lists 
Python :: python - exclude rowin data frame based on value 
Python :: python load pandas from pickle 
Python :: input stdout python 
Python :: install qt python 
Python :: python clear screen 
Python :: rotate image pyqt5 
Python :: check if user log in flask 
Python :: pandas columns add prefix 
Python :: python write yaml 
Python :: Square of numbers in non-decreasing order 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =