Questions tagged [pretty-print]

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.

1047 questions
110
votes
31 answers

Is there a pretty print for PHP?

I'm fixing some PHP scripts and I'm missing ruby's pretty printer. i.e. require 'pp' arr = {:one => 1} pp arr will output {:one => 1}. This even works with fairly complex objects and makes digging into an unknown script much easier. Is there some…
Aaron Lee
  • 5,287
  • 5
  • 24
  • 19
104
votes
10 answers

How to Pretty Print HTML to a file, with indentation

I am using lxml.html to generate some HTML. I want to pretty print (with indentation) my final result into an html file. How do I do that? This is what I have tried and got till now import lxml.html as lh from lxml.html import builder as…
bcosynot
  • 5,653
  • 10
  • 34
  • 47
78
votes
10 answers

A way to pretty print a C# object

I have a text box and I want to display a C# object in it in a human-readable way, just for debugging reasons. I don't want to use external libraries if possible. How do I do this?
Hui
  • 13,887
  • 8
  • 25
  • 20
77
votes
8 answers

How do I get Python's ElementTree to pretty print to an XML file?

Background I am using SQLite to access a database and retrieve the desired information. I'm using ElementTree in Python version 2.6 to create an XML file with that information. Code import sqlite3 import xml.etree.ElementTree as ET # NOTE: Omitted…
Kimbluey
  • 1,199
  • 2
  • 12
  • 23
76
votes
4 answers

Wanted: Command line HTML5 beautifier

Wanted A command line HTML5 beautifier running under Linux. Input Garbled, ugly HTML5 code. Possibly the result of multiple templates. You don't love it, it doesn't love you. Output Pure beauty. The code is nicely indented, has enough line breaks,…
blinry
  • 4,746
  • 4
  • 26
  • 31
68
votes
36 answers

How can I print a list of elements separated by commas?

I know how to do this in other languages, but not in C++, which I am forced to use here. I have a set of strings (keywords) that I'm printing to out as a list, and the strings need a comma between them, but not a trailing comma. In Java, for…
quandrum
  • 1,608
  • 1
  • 11
  • 14
65
votes
7 answers

How do I pretty-print existing JSON data with Java?

I have a compact JSON string, and I want to format it nicely in Java without having to deserialize it first -- e.g. just like jsonlint.org does it. Are there any libraries out there that provides this? A similar solution for XML would also be nice.
neu242
  • 15,796
  • 20
  • 79
  • 114
63
votes
5 answers

How to pretty print variables

Is there something like Ruby's awesome_print in Go? For example in Ruby you could write: require 'ap' x = {a:1,b:2} // also works for class ap x the output would be: { "a" => 1, "b" => 2 } closest thing that I could found is Printf("%#v", x)
Kokizzu
  • 24,974
  • 37
  • 137
  • 233
61
votes
4 answers

How to pretty print in ipython notebook via sympy?

I tried pprint, print, the former only prints Unicode version, and the latter doesn't do pretty prints. from sympy import symbols, Function import sympy.functions as sym from sympy import init_printing init_printing(use_latex=True) from sympy…
colinfang
  • 20,909
  • 19
  • 90
  • 173
60
votes
11 answers

Scala - how to print case classes like (pretty printed) tree

I'm making a parser with Scala Combinators. It is awesome. What I end up with is a long list of entagled case classes, like: ClassDecl(Complex,List(VarDecl(Real,float), VarDecl(Imag,float))), just 100x longer. I was wondering if there is a good way…
kornfridge
  • 5,102
  • 6
  • 28
  • 40
59
votes
5 answers

Memory dump formatted like xxd from gdb

I'm trying to inspect a buffer which contains a binary formatted message, but also contains string data. As an example, I'm using this C code: int main (void) { char buf[100] = "\x01\x02\x03\x04String Data\xAA\xBB\xCC"; return 0; } I'd…
FatalError
  • 52,695
  • 14
  • 99
  • 116
58
votes
8 answers

How do I print out a tree structure?

I'm trying to improve performance in our app. I've got performance information in the form of a tree of calls, with the following node class: public class Node { public string Name; // method name public decimal Time; // time spent in…
Simon
  • 25,468
  • 44
  • 152
  • 266
58
votes
4 answers

Pretty-printing output from javax.xml.transform.Transformer with only standard java api (Indentation and Doctype positioning)

Using the following simple code: package test; import java.io.*; import javax.xml.transform.*; import javax.xml.transform.stream.*; public class TestOutputKeys { public static void main(String[] args) throws TransformerException { //…
Alderath
  • 3,761
  • 1
  • 25
  • 43
55
votes
4 answers

How to handle widespread code format changes in a git repository

We have a project with around 500,000 lines of code, managed with git, much of it several years old. We're about to make a series of modifications to bring the older code into conformance with the developer community's current standards and best…
MarkusQ
  • 21,814
  • 3
  • 56
  • 68
54
votes
10 answers

When using Spring MVC for REST, how do you enable Jackson to pretty-print rendered JSON?

While developing REST services using Spring MVC, I would like render JSON 'pretty printed' in development but normal (reduced whitespace) in production.
Les Hazlewood
  • 18,480
  • 13
  • 68
  • 76
1 2
3
69 70