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 :: upload file in colab 
::  
Python :: how to sort in pandas 
:: pandas multiple string contains 
::  
::  
Python :: python get last modification time of file 
::  
Python :: python day from datetime 
Python :: xpath beautifulsoup 
Python ::  
Python :: sns seaborn set theme 
Python :: django install whitenoise 
::  
Python :: pandas drop values from column 
Python ::  
:: python os get output 
Python ::  
Python :: normalize column pandas 
Python :: import file to colab 
Python ::  
::  
Python ::  
::  
::  
Python :: opencv trim video duration 
::  
::  
Python :: rvec tvec ros message 
::  
ADD CONTENT
Topic
Content
Source link
Name
6+9 =