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
6
votes
4 answers

Suppress unicode prefix on strings when using pprint

Is there any clean way to supress the unicode character prefix when printing an object using the pprint module? >>> import pprint >>> pprint.pprint({u'foo': u'bar', u'baz': [u'apple', u'orange', u'pear', u'guava', u'banana'], u'hello':…
jterrace
  • 64,866
  • 22
  • 157
  • 202
6
votes
3 answers

How to override println behavior for reference types

I have a cyclic graph I created using dosync and ref-set. When I pass this to println I get a java.lang.StackOverflowError as I would expect, because it's effectively trying to print an infinitely-nested structure. I found that if I do (str…
Sonicsmooth
  • 2,673
  • 2
  • 22
  • 35
5
votes
1 answer

How to prettyprint f-Strings?

Attempting to pprint a dictionary from an f-String: import pprint as pp my_dict = { "key_a": ["here", "are", "the", "things"] , "key_b": ["that", "i", "want"] , "key_b": ["to", "share", "with", "the",…
Kermit
  • 4,922
  • 4
  • 42
  • 74
5
votes
4 answers

No matching distribution found for pprint

I am trying to install the requirements.txt file for skiptracer and it keeps saying ERROR: Could not find a version that satisfies the requirement pprint (from -r requirements.txt (line 7)) (from versions: none) ERROR: No matching distribution found…
user14216134
  • 61
  • 1
  • 3
5
votes
1 answer

How to line up columns when printing from 2d array in Python?

I want to display a simple 2D array in a tabular format with headings at the top, so that the values line up under the headings. Is there a way to do this? I have looked at pprint and printing using numpy but cannot get it to work. Here is what I…
user2127168
  • 91
  • 2
  • 11
4
votes
4 answers

Python - pprint large dict nicely?

I'm trying to pretty print dictionary which could get quite big and I want to make it as readable as possible. Though it still does not look like how I would manually write it (with new lines and indentation when needed). I'm trying it to have…
Andrius
  • 19,658
  • 37
  • 143
  • 243
4
votes
1 answer

How can I pretty print a nltk tree object?

I want to view if the result below is what I need in a visual way: import nltk sentence = [("the", "DT"), ("little", "JJ"), ("yellow", "JJ"), ("dog", "NN"), ("barked","VBD"), ("at", "IN"), ("the", "DT"), ("cat", "NN")] pattern = """NP:…
Lerner Zhang
  • 6,184
  • 2
  • 49
  • 66
4
votes
1 answer

How to pprint a tree data structure that is implemented using classes?

I know that pprint can pretty-print a nested list or dictionary, which are both types of tree structures, but I want to pprint a class-based tree with an arbitrary number of children, such that nodes are indented to the right depending on their…
J. Doe
  • 43
  • 4
4
votes
2 answers

Namedtuple formatted/pretty print in Python

Having trouble printing a namedtuple: Info = namedtuple('Info', ['type', 'value', 'x', 'y']) so that the values are aligned and with space(padding) between them, for example like so: Info( type='AAA', value=80000, x=16.4, y=164.2 ) Info(…
Yannis
  • 1,682
  • 7
  • 27
  • 45
4
votes
2 answers

How to ask sympy to don't translate bm to boldsymbol?

I'm in the situation where the enduser can define a variable name by himself. For instance: a variable called "tbm_al" is correct. In order to pprint variable as latex, I'm using sympy.latex and expecting to have something like "tbm" with "al" as…
user2652620
  • 464
  • 2
  • 17
3
votes
1 answer

Why does my code work from interactive shell, but not when run from a file?

I am trying to use the pprint module to check out some vars in Python, which I can happily do using the interactive shell and the code below: import pprint pp = pprint.PrettyPrinter() stuff = ['cakes','bread','mead'] pp.pprint(stuff) However, when…
ben
  • 1,583
  • 2
  • 11
  • 12
3
votes
2 answers

How to parse json in bash or pass curl output to python script

I'm looking to find some way to have pretty print of curl's output in json. I wrote short python script for this purpose, but it won't work with pipe Also I don't want to use subprocesses and run curl from them: So python: #!/usr/bin/python import…
kurd
  • 467
  • 1
  • 10
  • 18
3
votes
1 answer

I don't understand the width field in pprint in python

I don't understand this concept clearly. Could somebody give me some examples to demonstrate the concept for width in pprint in python?
user188276
3
votes
2 answers

pprint with hex numbers

I work with a number of json-like dicts. pprint is handy for structuring them. Is there a way to cause all ints in a pprint output to be printed in hex rather than decimal? For example, rather than: {66: 'far', 99: 'Bottles of the beer on the…
Travis Griggs
  • 21,522
  • 19
  • 91
  • 167
3
votes
1 answer

Why is Python 3's PrettyPrinter behaving differently from Python 2's, and how do I get the same behavior?

When I try running this code: from pprint import PrettyPrinter class MyPrettyPrinter(PrettyPrinter): def __init__(self, *args, **kwargs): PrettyPrinter.__init__(self, *args, **kwargs) def format(self, object, context, maxlevels,…
user541686
  • 205,094
  • 128
  • 528
  • 886
1 2
3
9 10