pretty-print

pretty print to a file in ruby

扶醉桌前 提交于 2020-01-22 10:33:13
问题 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 get_submap_from_final(all_mapping_file,final_map)}` It always prints to console and doesnt write to a file. Also there has to be an easier way to write to file in one line in ruby ? instead of doing File.new and then writing to a file ? 回答1: require 'pp' File.open

Split long XML tags in multiple lines with lxml

时光毁灭记忆、已成空白 提交于 2020-01-17 07:51:39
问题 My python (2.7) script is outputting the following XML using lxml library: <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="17dp" android:layout_marginTop="16dp" android:text="Button"/> I would like to output it in multiple lines, one per attribute: <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="17dp" android:layout

Pretty print XML data in JSP

ぐ巨炮叔叔 提交于 2020-01-17 03:55:06
问题 How do I pretty print (ie. with indentation) XML data in the JSP? I have the following code: <c:forEach items="${stuffs}" var="stuff"> <pre> <c:out value="${stuff}" escapeXml="true"/><br/> </pre> </c:forEach> But the problem is when ${stuff} is an unformatted XML, it will show in the jsp as one long XML data. I need it pretty-printed inside the <p> tag. 回答1: XSLT has a simple means of doing this via the xsl:output element. If you can apply an XSLT, I suggest using a stylesheet like this

Can I Google-Code-Prettify only a portion of the page? (run a javascript function on a specified portion of the page)

笑着哭i 提交于 2020-01-15 15:30:15
问题 I am using google-code-prettify to format some code that I am placing on my website. the code is dynamically added by me through a javascript function. The code submits fine… and prettifies beautifully. However, in order to get it to work I have to run the prettyPrint(); function after I insert the code. When I do this the existing blocks of code get indented and they are given a new line number. Here is what it looks like: Newly inserted code block: 1. function test(){ document.write("hello

Can I Google-Code-Prettify only a portion of the page? (run a javascript function on a specified portion of the page)

北城以北 提交于 2020-01-15 15:28:53
问题 I am using google-code-prettify to format some code that I am placing on my website. the code is dynamically added by me through a javascript function. The code submits fine… and prettifies beautifully. However, in order to get it to work I have to run the prettyPrint(); function after I insert the code. When I do this the existing blocks of code get indented and they are given a new line number. Here is what it looks like: Newly inserted code block: 1. function test(){ document.write("hello

Can I Google-Code-Prettify only a portion of the page? (run a javascript function on a specified portion of the page)

北慕城南 提交于 2020-01-15 15:28:11
问题 I am using google-code-prettify to format some code that I am placing on my website. the code is dynamically added by me through a javascript function. The code submits fine… and prettifies beautifully. However, in order to get it to work I have to run the prettyPrint(); function after I insert the code. When I do this the existing blocks of code get indented and they are given a new line number. Here is what it looks like: Newly inserted code block: 1. function test(){ document.write("hello

GDB 7.6 STL pretty print with gcc-4.8 and mac os 10.9

你。 提交于 2020-01-14 19:42:06
问题 I'm struggling to get the pretty prints as described here in gdb working on my mac. I downloaded the latest gdb through macports and using gcc-4.8 . I loaded the ~/.gdbinit file and the printers are registered, but whenever I call print myVector it gives me the raw output. Any suggestions what I could do? Thanks a lot guys! 回答1: To have pretty printer with libc++ (new library used in Clang++/LLVM) use this new pretty printer: https://github.com/koutheir/libcxx-pretty-printers The .gdbinit is

Pandas: cannot import name adjoin

牧云@^-^@ 提交于 2020-01-14 14:23:04
问题 From Wes: def side_by_side(*objs, **kwds): from pandas.core.common import adjoin space = kwds.get('space', 4) reprs = [repr(obj).split('\n') for obj in objs] print adjoin(space, *reprs) Apply below: import pandas as pd df1 = pd.DataFrame(np.random.rand(10,3)) df2 = pd.DataFrame(np.random.rand(10,3)) side_by_side(df1, df2) Throws error: ImportError Traceback (most recent call last) <ipython-input-25-2674cd8a228c> in <module>() 3 4 ----> 5 side_by_side(df1, df2) <ipython-input-24-9f441ebc9cb3>

Is there a pretty printing (or showing) abstraction in Haskell?

北慕城南 提交于 2020-01-13 19:55:11
问题 Is there no standard way to print out values for end-user consumption? Show is clearly more of a debugging convenience than something that would work for this purpose, given the conventions around its use and the constraint that read (show x) == x . For example, isn't there at least a simple package like class (Show a) => PShow a where pshow :: a -> String pshow = show pprint :: (PShow a) => a -> IO () pprint = putStrLn . pshow where instances do something like instance PShow MyType where

Use jq to Format Certain Fields as Compact?

淺唱寂寞╮ 提交于 2020-01-11 12:38:46
问题 Is jq the best choice for pretty-printing arbitrary JSON? cat my.json | jq . pretty-prints the given JSON, but expands every field on a separate line. But what if some of the fields are repetitive, such as a list of points? How can fields that match a pattern be formatted on a single line with --compact-output ? For example, format "coords" and "list" fields below on a single line: [ { "field1": { "a": "", "b": "" "list": [{ "name": "x", "score": 1, "rect": { "x": 156, "y": 245, "w": 35, "h":