當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。