Prettyprint (or pretty-print) is the application of any of various stylistic formatting conventions to text, source code, markup, and other similar kinds of content. These formatting conventions usually consist of changes in positioning, spacing, color, contrast, size and similar modifications intended to make the content easier for people to view, read and understand.
Questions tagged [pretty-print]
1047 questions
32
votes
6 answers
Python pretty XML printer with lxml
After reading from an existing file with 'ugly' XML and doing some modifications, pretty printing doesn't work. I've tried etree.write(FILE_NAME, pretty_print=True).
I have the following XML:

prosseek
- 182,215
- 215
- 566
- 871
32
votes
5 answers
How to Print "Pretty" String Output in Python
I have a list of dicts with the fields classid, dept, coursenum, area, and title from a sql query. I would like to output the values in a human readable format. I was thinking a Column header at the top of each and then in each column the…

themaestro
- 13,750
- 20
- 56
- 75
32
votes
7 answers
Pretty print XML in java 8
I have an XML file stored as a DOM Document and I would like to pretty print it to the console, preferably without using an external library. I am aware that this question has been asked multiple times on this site, however none of the previous…

Hungry
- 1,645
- 1
- 16
- 26
32
votes
4 answers
Custom indent width for BeautifulSoup .prettify()
Is there any way to define custom indent width for .prettify() function? From what I can get from it's source -
def prettify(self, encoding=None, formatter="minimal"):
if encoding is None:
return self.decode(True, formatter=formatter)
…

Bibhas Debnath
- 14,559
- 17
- 68
- 96
31
votes
8 answers
How do I pretty-print HTML with Nokogiri?
I wrote a web crawler in Ruby and I'm using Nokogiri::HTML to parse the page. I need to print the page out and while messing around in IRB I noticed a pretty_print method. However it takes a parameter and I can't figure out what it wants.
My crawler…

Jarsen
- 7,432
- 6
- 27
- 26
31
votes
5 answers
Pretty print a tree
Let's say I have a binary tree data structure defined as follows
type 'a tree =
| Node of 'a tree * 'a * 'a tree
| Nil
I have an instance of a tree as follows:
let x =
Node
(Node (Node (Nil,35,Node (Nil,40,Nil)),48,Node (Nil,52,Node…

Juliet
- 80,494
- 45
- 196
- 228
30
votes
34 answers
Do you try to make your code look pretty?
I might be one anal programmer, but I like code that looks good from a distance. I just found myself lining up a CSS style so that instead of this:
#divPreview {
text-align: center;
vertical-align: middle;
border: #779 1px solid;
…

Scott Evernden
- 39,136
- 15
- 78
- 84
30
votes
7 answers
Empty lines while using minidom.toprettyxml
I've been using a minidom.toprettyxml for prettify my xml file.
When I'm creating XML file and using this method, all works grate, but if I use it after I've modified the xml file (for examp I've added an additional nodes) and then I'm writing it…

Igal
- 4,603
- 14
- 41
- 66
29
votes
7 answers
Is there a better way to "Pretty Print" the json string than I'm using
I have json data comes server side.
In case I use the next code I get not pretty printed one line string:
print(String(bytes: jsonData, encoding: String.Encoding.utf8))
To make it pretty printed I use the next code:
if let json = try?…

Dmitry
- 2,963
- 2
- 21
- 39
29
votes
2 answers
Printing the same character several times without a loop
I would like to "beautify" the output of one of my Dart scripts, like so:
-----------------------------------------
OpenPGP signing notes from key `CD42FF00`
-----------------------------------------
And I wonder if there is a…

Diti
- 1,454
- 3
- 23
- 38
28
votes
7 answers
pretty print to a file in ruby
I am trying to pretty print a hash to a file.
I tried unix redirects [added different flags to it incrementally] :
`echo #{pp mymap} | tee summary.out 2>&1`
and File IO
my_file = File.new(@dir_+"/myfile.out",'w+')
my_file.puts `#{pp…

codeObserver
- 6,521
- 16
- 76
- 121
27
votes
3 answers
Java: Writing a DOM to an XML file (formatting issues)
I'm using org.w3c XML API to open an existing XML file. I'm removing some nodes , and I'm adding others instead.
The problem is that the new nodes that are added are written one after the other, with no newline and no indentation what so ever. While…

Vhaerun
- 12,806
- 16
- 39
- 38
27
votes
3 answers
How to format code in html / css / js/ php
I'm looking for a way to automatically format and color code I write in an HTML document. I know wikipedia does it, for example on the page: http://en.wikipedia.org/wiki/Nested_function
I'm sure there are libraries out there to do this, but I can't…

B T
- 57,525
- 34
- 189
- 207
26
votes
4 answers
best way to implement custom pretty-printers
Customizing pprint.PrettyPrinter
The documentation for the pprint module mentions that the method PrettyPrinter.format is intended to make it possible to customize formatting.
I gather that it's possible to override this method in a subclass, but…

intuited
- 23,174
- 7
- 66
- 88
24
votes
13 answers
C#: "Pretty" type name function?
The name properties of System.Type class return a strange result in case of generic types. Is there a way to get the type name in a format closer to the way I specified it?
Example: typeof(List).OriginalName == "List"

Harald Hoyer
- 515
- 4
- 14