当前位置: 首页>>代码示例>>Python>>正文


Python tabulate.PRESERVE_WHITESPACE属性代码示例

本文整理汇总了Python中tabulate.PRESERVE_WHITESPACE属性的典型用法代码示例。如果您正苦于以下问题:Python tabulate.PRESERVE_WHITESPACE属性的具体用法?Python tabulate.PRESERVE_WHITESPACE怎么用?Python tabulate.PRESERVE_WHITESPACE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在tabulate的用法示例。


在下文中一共展示了tabulate.PRESERVE_WHITESPACE属性的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_preserve_whitespace

# 需要导入模块: import tabulate [as 别名]
# 或者: from tabulate import PRESERVE_WHITESPACE [as 别名]
def test_preserve_whitespace():
    "Output: Default table output, but with preserved leading whitespace."
    tabulate_module.PRESERVE_WHITESPACE = True
    table_headers = ["h1", "h2", "h3"]
    test_table = [["  foo", " bar   ", "foo"]]
    expected = "\n".join(
        ["h1     h2       h3", "-----  -------  ----", "  foo   bar     foo"]
    )
    result = tabulate(test_table, table_headers)
    assert_equal(expected, result)

    tabulate_module.PRESERVE_WHITESPACE = False
    table_headers = ["h1", "h2", "h3"]
    test_table = [["  foo", " bar   ", "foo"]]
    expected = "\n".join(["h1    h2    h3", "----  ----  ----", "foo   bar   foo"])
    result = tabulate(test_table, table_headers)
    assert_equal(expected, result) 
开发者ID:astanin,项目名称:python-tabulate,代码行数:19,代码来源:test_output.py

示例2: serialise

# 需要导入模块: import tabulate [as 别名]
# 或者: from tabulate import PRESERVE_WHITESPACE [as 别名]
def serialise(self, fields=("name", "summary"), recurse=True, format=None):
        if format == "pinned":
            # user-specified fields are ignored/invalid in this case
            fields = ("pinned",)
        data = [OrderedDict([(f, getattr(self, f, None)) for f in fields])]
        if format == "human":
            table = gen_table(self, extra_cols=fields)
            tabulate.PRESERVE_WHITESPACE = True
            return tabulate.tabulate(table, headers="keys")
        if recurse and self.requires:
            deps = flatten_deps(self)
            next(deps)  # skip over root
            data += [d for dep in deps for d in dep.serialise(fields=fields, recurse=False)]
        if format is None or format == "python":
            result = data
        elif format == "json":
            result = json.dumps(data, indent=2, default=str, separators=(",", ": "))
        elif format == "yaml":
            result = oyaml.dump(data)
        elif format == "toml":
            result = "\n".join([toml.dumps(d) for d in data])
        elif format == "pinned":
            result = "\n".join([d["pinned"] for d in data])
        else:
            raise Exception("Unsupported format")
        return result 
开发者ID:wimglenn,项目名称:johnnydep,代码行数:28,代码来源:lib.py

示例3: adapter

# 需要导入模块: import tabulate [as 别名]
# 或者: from tabulate import PRESERVE_WHITESPACE [as 别名]
def adapter(data, headers, table_format=None, preserve_whitespace=False,
            **kwargs):
    """Wrap tabulate inside a function for TabularOutputFormatter."""
    keys = ('floatfmt', 'numalign', 'stralign', 'showindex', 'disable_numparse')
    tkwargs = {'tablefmt': table_format}
    tkwargs.update(filter_dict_by_key(kwargs, keys))

    if table_format in supported_markup_formats:
        tkwargs.update(numalign=None, stralign=None)

    tabulate.PRESERVE_WHITESPACE = preserve_whitespace

    return iter(tabulate.tabulate(data, headers, **tkwargs).split('\n')) 
开发者ID:dbcli,项目名称:cli_helpers,代码行数:15,代码来源:tabulate_adapter.py

示例4: parameter_count_table

# 需要导入模块: import tabulate [as 别名]
# 或者: from tabulate import PRESERVE_WHITESPACE [as 别名]
def parameter_count_table(model: nn.Module, max_depth: int = 3) -> str:
    """
    Format the parameter count of the model (and its submodules or parameters)
    in a nice table.

    Args:
        model: a torch module
        max_depth (int): maximum depth to recursively print submodules or
            parameters

    Returns:
        str: the table to be printed
    """
    count: typing.DefaultDict[str, int] = parameter_count(model)
    param_shape: typing.Dict[str, typing.Tuple] = {
        k: tuple(v.shape) for k, v in model.named_parameters()
    }

    table: typing.List[typing.Tuple] = []

    def format_size(x: int) -> str:
        # pyre-fixme[6]: Expected `int` for 1st param but got `float`.
        # pyre-fixme[6]: Expected `int` for 1st param but got `float`.
        if x > 1e5:
            return "{:.1f}M".format(x / 1e6)
        # pyre-fixme[6]: Expected `int` for 1st param but got `float`.
        # pyre-fixme[6]: Expected `int` for 1st param but got `float`.
        if x > 1e2:
            return "{:.1f}K".format(x / 1e3)
        return str(x)

    def fill(lvl: int, prefix: str) -> None:
        if lvl >= max_depth:
            return
        for name, v in count.items():
            if name.count(".") == lvl and name.startswith(prefix):
                indent = " " * (lvl + 1)
                if name in param_shape:
                    table.append((indent + name, indent + str(param_shape[name])))
                else:
                    table.append((indent + name, indent + format_size(v)))
                    fill(lvl + 1, name + ".")

    table.append(("model", format_size(count.pop(""))))
    fill(0, "")

    old_ws = tabulate.PRESERVE_WHITESPACE
    tabulate.PRESERVE_WHITESPACE = True
    tab = tabulate.tabulate(
        table, headers=["name", "#elements or shape"], tablefmt="pipe"
    )
    tabulate.PRESERVE_WHITESPACE = old_ws
    return tab 
开发者ID:facebookresearch,项目名称:fvcore,代码行数:55,代码来源:parameter_count.py


注:本文中的tabulate.PRESERVE_WHITESPACE属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。