pretty-print

Is there a pretty print for PHP?

只愿长相守 提交于 2019-11-27 05:01:06
问题 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? 回答1: Both print_r() and var_dump() will output visual representations of objects within PHP. $arr = array('one' => 1); print_r($arr); var_dump($arr); 回答2: This is what I use to print my arrays: <pre> <?php

How can I pretty-print JSON using Go?

丶灬走出姿态 提交于 2019-11-27 05:00:27
问题 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. 回答1: By pretty-print, I assume you mean indented, like so {

NumPy: Pretty print tabular data

陌路散爱 提交于 2019-11-27 04:39:06
I would like to print NumPy tabular array data, so that it looks nice. R and database consoles seem to demonstrate good abilities to do this. However, NumPy's built-in printing of tabular arrays looks like garbage: import numpy as np dat_dtype = { 'names' : ('column_one', 'col_two', 'column_3'), 'formats' : ('i', 'd', '|S12')} dat = np.zeros(4, dat_dtype) dat['column_one'] = range(4) dat['col_two'] = 10**(-np.arange(4, dtype='d') - 4) dat['column_3'] = 'ABCD' dat['column_3'][2] = 'long string' print(dat) # [(0, 0.0001, 'ABCD') (1, 1.0000000000000001e-005, 'ABCD') # (2, 9.9999999999999995e-007,

How to Print “Pretty” String Output in Python

佐手、 提交于 2019-11-27 04:14:34
问题 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 approrpiate output ie: CLASSID DEPT COURSE NUMBER AREA TITLE foo bar foo bar foo yoo hat yoo bar hat (obviously with standard alignment/spacing) How would I accomplish this in python? 回答1: Standard Python string formatting may suffice. # assume that your

Pretty-print a Map in Java

风流意气都作罢 提交于 2019-11-27 04:11:44
问题 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('=

Pretty print in lxml is failing when I add tags to a parsed tree

隐身守侯 提交于 2019-11-27 03:45:19
问题 I have an xml file that I'm using etree from lxml to work with, but when I add tags to it, pretty printing doesn't seem to work. >>> from lxml import etree >>> root = etree.parse('file.xml').getroot() >>> print etree.tostring(root, pretty_print = True) <root> <x> <y>test1</y> </x> </root> So far so good. But now >>> x = root.find('x') >>> z = etree.SubElement(x, 'z') >>> etree.SubElement(z, 'z1').attrib['value'] = 'val1' >>> print etree.tostring(root, pretty_print = True) <root> <x> <y>test1<

How do I print out a tree structure?

牧云@^-^@ 提交于 2019-11-27 03:11:22
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 method public List<Node> Children; } I want to print out the tree such that I can see lines between the nodes - something like in this question . What's an algorithm I can use in C# for doing that? Edit: Obviously I need to use recursion - but my attempts keep putting the lines in the wrong places. What I'm asking for is a specific algorithm that will print the

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

旧城冷巷雨未停 提交于 2019-11-27 01:42:16
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 code where I acccess the database, # pull data, and add elements to the tree tree = ET.ElementTree(root) # Pretty printing to Python shell for testing purposes from xml.dom import minidom print minidom.parseString(ET.tostring(root)).toprettyxml(indent = " ") ####### Here lies my problem ####### tree.write("New_Database.xml") Attempts I've tried using

Jax-rs json pretty output

淺唱寂寞╮ 提交于 2019-11-27 01:39:19
问题 in Java when i use the @Produces("application/json") annotation the output is not formated into human readable form. How do i achive that? 回答1: Just for the record, if you want to enable the pretty output only for some resources you can use the @JacksonFeatures annotation on a resource method. Here is example: @Produces(MediaType.APPLICATION_JSON) @JacksonFeatures(serializationEnable = { SerializationFeature.INDENT_OUTPUT }) public Bean resource() { return new Bean(); } 回答2: Create this class

Pretty print XML in java 8

两盒软妹~` 提交于 2019-11-27 01:37:59
问题 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 answers have worked for me. I am using java 8, so perhaps this is where my code differs from previous questions? I have also tried to set the transformer manually using code found from the web, however this just caused a not found error. Here is my