pretty-print

How to Pretty Print HTML to a file, with indentation

喜夏-厌秋 提交于 2019-11-28 03:22:56
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 (I am relatively new to Python and lxml) : import lxml.html as lh from lxml.html import builder as E sliderRoot=lh.Element("div", E.CLASS("scroll"), style="overflow-x: hidden; overflow-y: hidden;") scrollContainer=lh.Element("div", E.CLASS("scrollContainer"), style="width: 4340px;") sliderRoot.append(scrollContainer) print lh.tostring(sliderRoot, pretty_print = True, method="html") As you can see I am using the

Is there a pretty print for PHP?

亡梦爱人 提交于 2019-11-28 02:56:22
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 way to duplicate this functionality in PHP? Both print_r() and var_dump() will output visual representations of objects within PHP. $arr = array('one' => 1); print_r($arr); var_dump($arr); Joel Hernandez This is what I use to print my arrays: <pre> <?php print_r($your_array); ?> </pre> The magic comes with the pre tag. For simplicity, print_r() and

How can I pretty-print JSON using Go?

懵懂的女人 提交于 2019-11-28 02:51:15
Does anyone know of a simple way to pretty-print JSON output in Go? The stock http://golang.org/pkg/encoding/json/ package does not seem to include functionality for this (EDIT: it does, see accepted answer) and a quick google doesn't turn up anything obvious. Uses I'm looking for are both pretty-printing the result of json.Marshal and just formatting a string full of JSON from wherever, so it's easier to read for debug purposes. By pretty-print, I assume you mean indented, like so { "data": 1234 } rather than {"data":1234} The easiest way to do this is with MarshalIndent , which will let you

Python Source Formatter/Pretty Printer [closed]

折月煮酒 提交于 2019-11-28 02:44:11
问题 Is there an online or offline utility that will format/pretty-print Python source code? 回答1: http://pypi.python.org/pypi/PythonTidy is an excellent, simple script. I've found that PyLint and other code analysis tools all choke on pyrex, twisted and other modules. If you want formatting, just use PythonTidy . 回答2: Depends of what you mean by "format/pretty-print Python source code". There's Pygments that do syntax highlighting and you can try it online at Lodgeit (it's a pastebin). There's

How do I make Jackson's build() method pretty-print its JSON output?

半腔热情 提交于 2019-11-28 01:48:46
I use Spring, Jersey and Jackson to provide an API that produces JSON. My @Component has a @Get method that returns Response.ok(entity).build(). That output is very compact. How do I make that output pretty / formatted? 来源: https://stackoverflow.com/questions/6176881/how-do-i-make-jacksons-build-method-pretty-print-its-json-output

A way to pretty print a C# object

北战南征 提交于 2019-11-27 20:21:05
问题 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? 回答1: Serialize it to JSON. It can be done in the ToString() method like others suggested, but I don't think that is appropriate if you are going to use that for debugging only. 回答2: If you use Json then I would suggest using Newtonsofts Json library and then you can output the entire object in Json notation and it

Print a list of space-separated elements in Python 3

这一生的挚爱 提交于 2019-11-27 18:32:34
I have a list L of elements, say natural numbers. I want to print them in one line with a single space as a separator. But I don't want a space after the last element of the list (or before the first). In Python 2, this can easily be done with the following code. The implementation of the print statement (mysteriously, I must confess) avoids to print an extra space before the newline. L = [1, 2, 3, 4, 5] for x in L: print x, print However, in Python 3 it seems that the (supposedly) equivalent code using the print function produces a space after the last number: L = [1, 2, 3, 4, 5] for x in L:

Pretty print a tree

给你一囗甜甜゛ 提交于 2019-11-27 18:00:37
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 (Nil,53,Nil))), 80,Node (Node (Nil,82,Node (Nil,83,Nil)),92,Node (Nil,98,Nil))) I'm trying to pretty-print the tree into something easy to interpret. Preferably, I'd like to print the tree in a console window like this: _______ 80 _______ / \ _ 48 _ _ 92 _ / \ / \ 35 52 82 98 \ \ / 40 53 83 What's an easy way to get my tree to output in that format? If you want it

Pretty-print a Map in Java

ε祈祈猫儿з 提交于 2019-11-27 17:25:03
I am looking for a nice way to pretty-print a Map . map.toString() gives me: {key1=value1, key2=value2, key3=value3} I want more freedom in my map entry values and am looking for something more like this: key1="value1", key2="value2", key3="value3" I wrote this little piece of code: StringBuilder sb = new StringBuilder(); Iterator<Entry<String, String>> iter = map.entrySet().iterator(); while (iter.hasNext()) { Entry<String, String> entry = iter.next(); sb.append(entry.getKey()); sb.append('=').append('"'); sb.append(entry.getValue()); sb.append('"'); if (iter.hasNext()) { sb.append(',')

How do I get the compact form of pretty-printed JSON code?

家住魔仙堡 提交于 2019-11-27 17:21:58
问题 How do I make Jackson's build() method pretty-print its JSON output? Here is an example that pretty-prints the ugly form of JSON code. I need to take the nice version of JSON code then convet it to ugly fom. How can it be done? I need to convert this: { "one" : "AAA", "two" : [ "BBB", "CCC" ], "three" : { "four" : "DDD", "five" : [ "EEE", "FFF" ] } } to this: {"one":"AAA","two":["BBB","CCC"],"three":{"four":"DDD","five":["EEE","FFF"]}} I tried to remove '\n', '\t', and ' ' characters; but