Questions tagged [pprint]

Pprint is a Python module used for “pretty-printing” arbitrary data structures.

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.

136 questions
1
vote
2 answers

I have a problem with pprint in python

I have looked into the pprint function, which i tried below: from pprint import pprint a = [[1,2],[3,4]] pprint(a) But it didn't give me what i want, which is: 1 2 3 4 Is there a simple way to solve this ?
user188276
1
vote
0 answers

python 'pformat' ignores 'compact'=False?

I want to print dictionaries in a formatted way, so I tried to use prettyprinter. I wanted to get a result with separate line by each value, something like this: [ { "interface": "mgmt0", "mac": "00:07:70:E6:51:BA", "ip":…
me in let
  • 13
  • 3
1
vote
1 answer

TypeError using pprint on Counter() objects that have been updated (bit of an edge case)

Under some circumstances, Python pretty print (pprint.pprint) produces a TypeError, and it caught me a bit by surprise. We can create a Counter object from (eg) a list of integers and pretty print it: from collections import Counter from pprint…
redacted code
  • 192
  • 10
1
vote
0 answers

Pretty printing Python dictionary/lists in "Black style"

I don't really fancy the way Python's pprint formats the output. E.g. import pprint from datetime import datetime d = { 'a': [ { '123': datetime(2021, 11, 15, 0, 0), '456': 'cillum dolore eu fugiat nulla pariatur.…
Ferrard
  • 2,260
  • 3
  • 22
  • 26
1
vote
1 answer

Get sympy to pprint sin(a_n) with s(a_n)

I'm trying to get sympy to pprint matrices with trig functions with the first letter instead of the shortened term in order to save space. So sin(a_1) will look like sa_1. Right now I'm printing to text then running a find and replace. (I'm new to…
Manju
  • 15
  • 3
1
vote
1 answer

pretty print python code from jupyter notebook

How to pretty print / display a piece of code from jupyter notebook, here is a (failing) example of what I am trying to do: Ideally, I would ask for some other pprint that would print the code of foo with nice coloured annotation similar to how…
ntg
  • 12,950
  • 7
  • 74
  • 95
1
vote
1 answer

Could not install packages due to an EnvironmentError https://pypi.org/simple/pprint/

issue in python pip pkg : pprint /bug_bounty/HawkScan$ ls CHANGELOG.md config.pyc Dockerfile __init__.py README.md requirements.txt sites sublist config.py dico.txt hawkscan.py modules report setup.py static …
Grey_ph4ntom
  • 21
  • 1
  • 3
1
vote
1 answer

Can I force pprint to print a set number of elements per line instead of width?

I have a list of of values and would like to print it in such a way that after a certain number of elements pprint forces a new line. I'm working with a dynamic data set and it's not possible to predict what the width of each new desired line will…
defarm
  • 81
  • 1
  • 12
1
vote
1 answer

Pretty formatted numpy JSON encoder

I was looking for a method to save numpy data with json while preserving numpy's human readable pretty print format. Inspired by this answer, I opted to use pprint instead of base64 to write the data with my desired formatting, so that…
Fnord
  • 5,365
  • 4
  • 31
  • 48
1
vote
2 answers

How to print without new line using pprint

How to pprint.pformat string as like print. I am using pprint because I need to use indent test = 'google\\nfirefox' import pprint pprint.pformat(test) output is "'enable\\\\nshow'" expected result is like print (test) google\nfirefox
user11727742
1
vote
0 answers

Python Pprint Pformat to return HTML string instead of regular string

I know we can use pformat to return a formated string of a dictionary in python, but it's not in html format. How can I get the html format?
Aminah Nuraini
  • 18,120
  • 8
  • 90
  • 108
1
vote
2 answers

Best way to print a dict with \n or \t characters in keys or values in python?

Essentially, I want to print a dictionary such that it uses str() instead of repr() to stringify its keys and values. This would be especially useful when saving a traceback string in some json. But this appears to be much more difficult than I…
mavix
  • 2,488
  • 6
  • 30
  • 52
1
vote
0 answers

How to print dictionary neatly?

I have a dictionary named settings. >>>print settings {u'key1': u'value1', u'key2': u'value2', u'key3': u'value3'} I wanted the output like this: key1: value1 key2: value2 key3: value3 can pprint do this? If not then which module does it? I'm…
Chang Zhao
  • 631
  • 2
  • 8
  • 24
1
vote
2 answers

pprint: UnicodeEncodeError: 'ascii' codec can't encode character

This is driving me crazy. I'm trying to pprint a dict with an é char, and it throws me out. I'm using Python 3: from pprint import pprint knights = {'gallahad': 'the pure', 'robin': 'the bravé'} pprint (knights) Error: File…
user2071786
  • 121
  • 1
  • 10
1
vote
2 answers

Cannot find variables in a list of dictionaries

I am trying to ge around with APIs in general. To test this I coded this little snippet of code to get a list of all the channels on the Swedish national public service radio, and I want to print the ID and NAME of the channels: import requests as…