标签: pretty-print

Haskell:`show`的变体,它不会在引号中包装String和Char

我想的变体show(我们称之为label),其行为就像show,只是它不换行StringS IN " "CharS IN ' '.例子:

> label 5
"5"
> label "hello"
"hello"
> label 'c'
"c"
Run Code Online (Sandbox Code Playgroud)

我尝试手动实现这个,但我碰到了一些墙.这是我尝试过的:

{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances #-}
module Label where

class (Show a) => Label a where
    label :: a -> String

instance Label [Char] where
    label str = str

instance Label Char where
    label c = [c]

-- Default case
instance Show a => Label a …
Run Code Online (Sandbox Code Playgroud)

haskell pretty-print

3
推荐指数
1
解决办法
2323
查看次数

如何格式化(漂亮打印)多维数组进行调试?

我见过一些在线漂亮的打印模块代码.有人知道将多维数组格式化为可读显示吗?

例如,翻译这个:

array(83){[0] => array(2){["name"] => string(11)"CE2 Options"["type"] => string(5)"title"} [1] => array(1){["type"] => string(4)"open"} [2] => array(5){["name"] => string(8)"Template"["desc"] = > string(638)"test description"["id"] => string(9)"my_theme"["type"] => string(14)"selectTemplate"["options"] => array(13){

进入这...

array(83) { 
    [0]=> array(2) { ["name"]=> string(11) "My Options" ["type"]=> string(5) "title" } 
    [1]=> array(1) { ["type"]=> string(4) "open" } 
    [2]=> array(5) { 
        ["name"]=> string(8) "Template" 
        ["desc"]=> string(638) "Test description" 
        ["id"]=> string(9) "my_theme" 
        ["type"]=> string(14) "selectTemplate" 
        ["options"]=> array(13) { 
            [0]=> string(10) "test" 
Run Code Online (Sandbox Code Playgroud)

pretty-print

3
推荐指数
1
解决办法
1万
查看次数

在Firefox和IE中使用XSLT进行XML到XML的转换

我从几种XML格式转换为一种标准.我的XSL看起来如下:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
    <xsl:output method="xml" encoding="UTF-8" indent="yes" omit-xml-declaration="yes"/>

    <xsl:template match="list | store">
        <list>
            <xsl:for-each select="item | product | product-store">
            <item>
                <name>
                    <xsl:choose>
                        <xsl:when test="name"><xsl:value-of select="substring-before(name, ' ')" /></xsl:when>
                        <xsl:otherwise><xsl:value-of select="name | title" /></xsl:otherwise>
                    </xsl:choose>
                </name>
                <desc>
                    <xsl:choose>
                        <xsl:when test="name"><xsl:value-of select="substring-after(name, ' ')" /></xsl:when>
                        <xsl:otherwise><xsl:value-of select="desc" /></xsl:otherwise>
                    </xsl:choose>
                </desc>
                <nr><xsl:value-of select="index | number" /></nr>
            </item>
            </xsl:for-each>
        </list>
    </xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)

我的示例XML是

<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<?xml-stylesheet type="text/xsl" href="transform.xsl"?>
<list>
    <item>
      <index>1362242627</index>
      <name>test 22</name>  
    </item>
    <item>
      <index>2362625609</index>
      <name>test …
Run Code Online (Sandbox Code Playgroud)

xml xslt cross-browser pretty-print mime-types

3
推荐指数
1
解决办法
5547
查看次数

如何在Python中缩进pprint?

我正在尝试缩进pprint的输出,以便使用pprint获得8个空格的缩进。我使用的代码是:

import numpy as np
from pprint import pprint
A = np.array([1, 2, 3, 4])
f = open("log.txt", 'w')
n = 2
for i in range(n):
    A = A + 1
    f.writelines(list(u'    \u27B3 - %s\n'.encode('utf-8') % i for i in A))
    pprint(globals())
Run Code Online (Sandbox Code Playgroud)

输出量

import numpy as np
from pprint import pprint
A = np.array([1, 2, 3, 4])
f = open("log.txt", 'w')
n = 2
for i in range(n):
    A = A + 1
    f.writelines(list(u'    \u27B3 - %s\n'.encode('utf-8') % i for …
Run Code Online (Sandbox Code Playgroud)

python pretty-print indentation pprint

3
推荐指数
1
解决办法
2544
查看次数

Ruby(或Shell)中的漂亮打印HTML

有没有办法在mac上从命令行打印HTML或XML字符串?试着用Ruby做到这一点.有任何想法吗?我已经考虑过XSLT,以及编写自己的解析器,但这些都非常复杂.寻找已经存在的东西.

html ruby xml unix pretty-print

2
推荐指数
1
解决办法
1940
查看次数

Python中的漂亮打印格式问题

 str = ""
 for i in range(1,91):
     str = str + '-'

 print "+", '{:^90}'.format(str), "+"
 for elem in cursor:
     print "|", '{:^8}'.format(elem['classid']), \
           "|", '{:^8}'.format(elem['dept']), \
           "|", '{:^8}'.format(elem['coursenum']), \
           "|", '{:^8}'.format(elem['area']), \
           "|", '{:<46}'.format(elem['title']), \
          "|"
 print "+", '{:^90}'.format(str), "+"
Run Code Online (Sandbox Code Playgroud)

我有以下代码来尝试打印出db查询的结果.在独立文件中,它打印以下输出:

+ ------------------------------------------------------------------------------------------ +
| centered | centered | centered | centered | 12                                             |
| centered | centered | centered | centered | 12                                             |
| centered | centered | centered | centered | 12                                             |
+ ------------------------------------------------------------------------------------------ …
Run Code Online (Sandbox Code Playgroud)

python pretty-print

2
推荐指数
1
解决办法
1286
查看次数

我可以从注释或Spring MVC控制器配置Jackson JSON漂亮的打印吗?

我正在使用Jackson 1.9.6(codehaus)在Spring MVC应用程序中对我的响应主体进行JSON序列化,而我却无法找到配置漂亮打印的方法.我能够找到的所有代码示例(比如thisthis)都涉及到ObjectMapper或者实例化ObjectWriter,但我目前还没有使用其他任何实例化.我甚至不知道在哪里放这个代码.我所有的Jackson配置都是通过注释序列化为JSON的POJO来处理的.

有没有办法在注释中指定漂亮的打印?我认为他们会把它放在@JsonSerialize中,但它看起来不像.

我要序列化的类看起来像这样:

@JsonAutoDetect
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
public class JSONObject implements Serializable{...}
Run Code Online (Sandbox Code Playgroud)

我的Spring控制器方法如下所示:

@RequestMapping(method = RequestMethod.GET)
public @ResponseBody List<Object> getMessagesAndUpdates(HttpServletRequest request, HttpServletResponse response) {
    JSONObject jsonResponse = new JSONObject();
    .
    .
    .
    //this will generate a non-pretty-printed json response.  I want it to be pretty-printed.
    return jsonResponse;
}
Run Code Online (Sandbox Code Playgroud)

spring json pretty-print jackson

2
推荐指数
1
解决办法
4263
查看次数

PrettyPrint缩进/换行每个级别

PrettyPrint很棒,但我遇到了以下问题.

我有一个像那样打印的结构:

{ 'table': { 'tr': [ { 'tr': { 'td': [ {'td': 'Period'},
                                       {'td': 'G-A:B '},
                                       {'td': 'SA -A:B '},
                                       {'td': 'PIM-A:B  '},
                                       {'td': 'PP-A:B '},
                                       {'td': 'SH-A:B'}]}},
                     { 'tr': { 'td': [ {'td': '1'},
                                       {'td': '2:2'},
                                       {'td': '14:10'},
                                       {'td': '4:8'},
                                       {'td': '1:1'},
                                       {'td': '0:0'}]}},
                     { 'tr': { 'td': [ {'td': '2'},
                                       {'td': '2:2'},
                                       {'td': '13:11'},
                                       {'td': '37:27'},
                                       {'td': '0:0'},
                                       {'td': '0:0'}]}},
                     { 'tr': { 'td': [ {'td': '3'},
                                       {'td': '0:1'},
                                       {'td': '11:13'},
                                       {'td': '0:8'},
                                       {'td': '0:0'},
                                       {'td': '0:0'}]}}, …
Run Code Online (Sandbox Code Playgroud)

python pretty-print

2
推荐指数
1
解决办法
185
查看次数

在HttpConfiguration实例中的ASP.NET Web API应用程序中处理json pretty print param

我需要在ASP.NET Web API应用程序中添加和处理可选的"漂亮"参数.当用户发送"pretty = true"时,应用程序响应应该看起来像带有缩进的人类可读的json.当用户发送"pretty = false"或根本不发送此参数时,他必须得到没有空格符号的json作为响应.

这就是我所拥有的: Global.asax.cs

public class WebApiApplication
        : HttpApplication
    {
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        }
    }
Run Code Online (Sandbox Code Playgroud)

WebApiConfig.cs

public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            config.Filters.Add(new ValidateModelAttribute());
            config.Formatters.JsonFormatter.SerializerSettings = new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore,
                Formatting = Newtonsoft.Json.Formatting.Indented
            };
            config.Formatters.JsonFormatter.SerializerSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter());
...
Run Code Online (Sandbox Code Playgroud)

如您所知,我需要在Register方法中使用这样的逻辑:

config.Formatters.JsonFormatter.SerializerSettings = new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore,
                Formatting = Newtonsoft.Json.Formatting.Indented
            };
if(prettyPrint) // must be extracted from request and passed here somehow
{ …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc json pretty-print json.net asp.net-web-api

2
推荐指数
1
解决办法
1636
查看次数

如何在Haskell中编写内联YAML(流式)?

Data.Yaml用来以人类可读的格式存储一些数据.但是,数据的某些部分是数字列表或矩阵.YAML输出,块序列样式,非常详细:

- - 1
  - 2
  - 3
- - 4
  - 5
Run Code Online (Sandbox Code Playgroud)

相反,我希望这些部分以流程序列样式进行编码,就像

[[1,2,3],[4,5]]
Run Code Online (Sandbox Code Playgroud)

有办法怎么做?

yaml haskell pretty-print aeson

2
推荐指数
1
解决办法
445
查看次数