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
13
votes
1 answer

pprint sorting dicts but not sets?

I know that dicts and sets aren't ordered, so equal sets or dicts may print differently (all tests with Python 3.6.1): >>> for obj in {0, 8}, {8, 0}, {0:0, 8:8}, {8:8, 0:0}: print(obj) {0, 8} {8, 0} {0: 0, 8: 8} {8: 8, 0: 0} And I just…
Stefan Pochmann
  • 27,593
  • 8
  • 44
  • 107
12
votes
2 answers

How to force pprint to print one list/tuple/dict element per line?

How can I force pprint() to print one list/tuple/dict element per line? >>> from pprint import pprint >>> my_var = ['one', 'two', ('red','green'), {'state' : 'Oregon', 'city' : 'Portland'}] >>> pprint(my_var) ['one', 'two', ('red', 'green'),…
Rob Bednark
  • 25,981
  • 23
  • 80
  • 125
11
votes
3 answers

pretty-printing a record using a custom method in Clojure

In Clojure 1.5.0, how can I provide a custom pretty-printer for my own record type, defined with defrecord. (defrecord MyRecord [a b]) (defmethod print-method MyRecord [x ^java.io.Writer writer] (print-method (:a x) writer)) (defmethod print-dup…
namin
  • 37,139
  • 8
  • 58
  • 74
10
votes
1 answer

error: Could not find a version that satisfies the requirement pprint (from -r requirements.txt (line 67)) (from versions: none)

I am trying to install a NLP suite on my macbook pro, which is updated to the most recent software version Catalina 10.15.6. So far, I have installed Anaconda 3.8, created a version 3.7 NLP environment by conda create -n NLP python=3.7, and…
confusedallthetime
  • 155
  • 1
  • 3
  • 9
10
votes
4 answers

Python 3.x: alternative pprint implementation

Standard pprint module is nice when deals with lists, dicts and so on. But sometimes completely unusable with custom classes: The only way to make it print usable information about an object of some class is to override __repr__, but what if my…
Equidamoid
  • 1,447
  • 1
  • 13
  • 24
9
votes
1 answer

Does Scala offer functionality similar to Pretty Print in Python?

Does Scala offer functionality similar to Pretty Print pprint in Python?
defoo
  • 5,159
  • 11
  • 34
  • 39
9
votes
0 answers

How to make pprint.pprint understand newline character?

>>> a = '1\n2\n3' >>> pprint(a) '1\n2\n3' What i want it for pprint to print out 1 2 3 Is that possible?
lionel319
  • 1,180
  • 2
  • 17
  • 31
9
votes
3 answers

PPrint not working (Python)?

I'm trying to use Python's pprint on a dictionary but for some reason it isn't working. Here's my code (I'm using PyCharm Pro as my IDE):` from pprint import pprint message = "Come on Eileen!" count = {} for character in message: …
Roby Leahy
  • 113
  • 1
  • 5
9
votes
3 answers

How to indent with pprint in Python?

I am trying to indent the output of pprint so that I will get an 8 space indentation with pprint. The code I used is: import numpy as np from pprint import pprint A = np.array([1, 2, 3, 4]) f = open("log.txt", 'w') n = 2 for i in range(n): A = A…
Tom Kurushingal
  • 6,086
  • 20
  • 54
  • 86
8
votes
1 answer

pprint with custom float formats

I have a nested dictionary structure with tuple keys. Here's what an entry looks like when I pretty-print the dictionary using pprint: ... ('A', 'B'): {'C': 0.14285714285714285, 'D': 0.14285714285714285, 'E':…
Berk Özbalcı
  • 3,016
  • 3
  • 21
  • 27
8
votes
1 answer

Can't import pprint

Programming newbie here. Whenever I attempt to 'import pprint' in the Python IDLE, I get the following error: >>> import pprint Traceback (most recent call last): File "", line 1, in import pprint File…
Thrynn
  • 199
  • 2
  • 2
  • 11
7
votes
2 answers

How to remove timestamps from celery pprint output?

When running the celery worker then each line of the output of the pprint is always prefixed by the timestamp and also is being stripped. This makes it quite unreadable: [2015-11-05 16:01:12,122: WARNING/Worker-2] { [2015-11-05 16:01:12,122:…
Ikar Pohorský
  • 4,617
  • 6
  • 39
  • 56
6
votes
1 answer

Printing formatted floats in nested tuple of mixed type

I have a list of tuples where the entries in the tuples are mixed type (int, float, tuple) and want to print each element of the list on one line. Example list: [('520', (0.26699505214910974, 9.530913611077067e-22, 1431, …
Sal
  • 1,653
  • 6
  • 23
  • 36
6
votes
1 answer

Combine reprlib and pprint in Python?

Can I have pretty printed data output as in pprint.pprint (new lines, indentation), but also shortened lists as in reprlib.repr at the same time? An ugly hack seems to be pprint(eval(reprlib.repr(data))), but is there a better way?
Gere
  • 12,075
  • 18
  • 62
  • 94
6
votes
3 answers

Indentation of pformat() output

I have a function that uses pformat() to convert a dictionary to a string (irrelevant: string will be later inserted with write() in a .py file). So MY_DCT = {1: 11, 2: 22, 3: 33} would become a string like this: MY_DCT = { 1: 11, 2: 22, …
user
  • 5,370
  • 8
  • 47
  • 75
1
2
3
9 10