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


Python pretty.pretty方法代码示例

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


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

示例1: repr_pretty_delegate

# 需要导入模块: from IPython.lib import pretty [as 别名]
# 或者: from IPython.lib.pretty import pretty [as 别名]
def repr_pretty_delegate(obj):
    # If IPython is already loaded, then might as well use it. (Most commonly
    # this will occur if we are in an IPython session, but somehow someone has
    # called repr() directly. This can happen for example if printing an
    # container like a namedtuple that IPython lacks special code for
    # pretty-printing.)  But, if IPython is not already imported, we do not
    # attempt to import it. This makes patsy itself faster to import (as of
    # Nov. 2012 I measured the extra overhead from loading IPython as ~4
    # seconds on a cold cache), it prevents IPython from automatically
    # spawning a bunch of child processes (!) which may not be what you want
    # if you are not otherwise using IPython, and it avoids annoying the
    # pandas people who have some hack to tell whether you are using IPython
    # in their test suite (see patsy bug #12).
    if optional_dep_ok and "IPython" in sys.modules:
        from IPython.lib.pretty import pretty
        return pretty(obj)
    else:
        return _mini_pretty(obj) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:20,代码来源:util.py

示例2: repr_pretty_impl

# 需要导入模块: from IPython.lib import pretty [as 别名]
# 或者: from IPython.lib.pretty import pretty [as 别名]
def repr_pretty_impl(p, obj, args, kwargs=[]):
    name = obj.__class__.__name__
    p.begin_group(len(name) + 1, "%s(" % (name,))
    started = [False]
    def new_item():
        if started[0]:
            p.text(",")
            p.breakable()
        started[0] = True
    for arg in args:
        new_item()
        p.pretty(arg)
    for label, value in kwargs:
        new_item()
        p.begin_group(len(label) + 1, "%s=" % (label,))
        p.pretty(value)
        p.end_group(len(label) + 1, "")
    p.end_group(len(name) + 1, ")") 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:20,代码来源:util.py

示例3: testUnicodeInputAndOutput

# 需要导入模块: from IPython.lib import pretty [as 别名]
# 或者: from IPython.lib.pretty import pretty [as 别名]
def testUnicodeInputAndOutput(self):
    # "猫" is "cats" in simplified Chinese and its representation requires
    # three bytes. Force reading only one byte at a time and ensure that the
    # character is preserved.
    _system_commands._PTY_READ_MAX_BYTES_FOR_TEST = 1
    cmd = u'r = %shell read result && echo "You typed: $result"'
    run_cell_result = self.run_cell(cmd, provided_inputs=[u'猫\n'])
    captured_output = run_cell_result.output

    self.assertEqual('', captured_output.stderr)
    self.assertEqual(u'猫\nYou typed: 猫\n', captured_output.stdout)
    result = self.ip.user_ns['r']
    self.assertEqual(0, result.returncode)
    self.assertEqual(u'猫\nYou typed: 猫\n', result.output)

    # Ensure that ShellResult objects don't have a "pretty" representation. This
    # ensures that no output is printed if the magic is the only statement in
    # the cell.
    self.assertEqual(u'', pretty.pretty(result)) 
开发者ID:googlecolab,项目名称:colabtools,代码行数:21,代码来源:test_system_commands.py

示例4: test_multivector

# 需要导入模块: from IPython.lib import pretty [as 别名]
# 或者: from IPython.lib.pretty import pretty [as 别名]
def test_multivector(self, g2):
        p = g2.MultiVector(np.arange(4, dtype=np.int32))
        assert pretty.pretty(p) == repr(p)

        expected = textwrap.dedent("""\
        MultiVector(Layout([1, 1],
                           ids=BasisVectorIds.ordered_integers(2),
                           order=BasisBladeOrder.shortlex(2),
                           names=['', 'e1', 'e2', 'e12']),
                    [0, 1, 2, 3],
                    dtype=int32)""")

        # ipython printing only kicks in in ugly mode
        try:
            clifford.ugly()
            assert pretty.pretty(p) == expected
        finally:
            clifford.pretty() 
开发者ID:pygae,项目名称:clifford,代码行数:20,代码来源:test_clifford.py

示例5: test_multivector_predefined

# 需要导入模块: from IPython.lib import pretty [as 别名]
# 或者: from IPython.lib.pretty import pretty [as 别名]
def test_multivector_predefined(self):
        """ test the short printing of predefined layouts """
        from clifford.g2 import layout as g2
        p_i = g2.MultiVector(np.arange(4, dtype=np.int32))
        p_f = g2.MultiVector(np.arange(4, dtype=np.float64))
        assert pretty.pretty(p_i) == repr(p_i)
        assert pretty.pretty(p_f) == repr(p_f)

        # float is implied
        expected_i = "clifford.g2.layout.MultiVector([0, 1, 2, 3], dtype=int32)"
        expected_f = "clifford.g2.layout.MultiVector([0.0, 1.0, 2.0, 3.0])"

        # ipython printing only kicks in in ugly mode
        try:
            clifford.ugly()
            assert pretty.pretty(p_i) == expected_i
            assert pretty.pretty(p_f) == expected_f
        finally:
            clifford.pretty() 
开发者ID:pygae,项目名称:clifford,代码行数:21,代码来源:test_clifford.py

示例6: test_invariants

# 需要导入模块: from IPython.lib import pretty [as 别名]
# 或者: from IPython.lib.pretty import pretty [as 别名]
def test_invariants(self, g2):
        e1, e2 = g2.basis_vectors_lst

        matrix = np.array([[ 0, 1],
                           [-1, 0]])
        f = transformations.OutermorphismMatrix(matrix, g2)

        # test the vector transform is as requested
        assert f(e1) == -e2
        assert f(e2) == e1
        # test the generalization is correct
        assert f(e1^e2) == f(e1)^f(e2)
        assert f(g2.scalar) == g2.scalar

        # test that distributivity is respected
        assert f(g2.scalar + 2*e1 + 3*(e1^e2)) == f(g2.scalar) + 2*f(e1) + 3*f(e1^e2)

        assert pretty.pretty(f) == textwrap.dedent("""\
        OutermorphismMatrix(array([[ 0,  1],
                                   [-1,  0]]),
                            Layout([1, 1],
                                   ids=BasisVectorIds(['u', 'v']),
                                   order=BasisBladeOrder.shortlex(2),
                                   names=['', 'eu', 'ev', 'euv']))""") 
开发者ID:pygae,项目名称:clifford,代码行数:26,代码来源:test_transformations.py

示例7: __repr__

# 需要导入模块: from IPython.lib import pretty [as 别名]
# 或者: from IPython.lib.pretty import pretty [as 别名]
def __repr__(self):
        bindings = ['edges', 'nodes', 'source', 'destination', 'node', 
                    'edge_label', 'edge_color', 'edge_size', 'edge_weight', 'edge_title', 'edge_icon', 'edge_opacity',
                    'edge_source_color', 'edge_destination_color',
                    'point_label', 'point_color', 'point_size', 'point_weight', 'point_title', 'point_icon', 'point_opacity',
                    'point_x', 'point_y']
        settings = ['height', 'url_params']

        rep = {'bindings': dict([(f, getattr(self, '_' + f)) for f in bindings]),
               'settings': dict([(f, getattr(self, '_' + f)) for f in settings])}
        if util.in_ipython():
            from IPython.lib.pretty import pretty
            return pretty(rep)
        else:
            return str(rep) 
开发者ID:graphistry,项目名称:pygraphistry,代码行数:17,代码来源:plotter.py

示例8: test_PushbackAdapter

# 需要导入模块: from IPython.lib import pretty [as 别名]
# 或者: from IPython.lib.pretty import pretty [as 别名]
def test_PushbackAdapter():
    it = PushbackAdapter(iter([1, 2, 3, 4]))
    assert it.has_more()
    assert six.advance_iterator(it) == 1
    it.push_back(0)
    assert six.advance_iterator(it) == 0
    assert six.advance_iterator(it) == 2
    assert it.peek() == 3
    it.push_back(10)
    assert it.peek() == 10
    it.push_back(20)
    assert it.peek() == 20
    assert it.has_more()
    assert list(it) == [20, 10, 3, 4]
    assert not it.has_more()

# The IPython pretty-printer gives very nice output that is difficult to get
# otherwise, e.g., look how much more readable this is than if it were all
# smooshed onto one line:
# 
#    ModelDesc(input_code='y ~ x*asdf',
#              lhs_terms=[Term([EvalFactor('y')])],
#              rhs_terms=[Term([]),
#                         Term([EvalFactor('x')]),
#                         Term([EvalFactor('asdf')]),
#                         Term([EvalFactor('x'), EvalFactor('asdf')])],
#              )
#              
# But, we don't want to assume it always exists; nor do we want to be
# re-writing every repr function twice, once for regular repr and once for
# the pretty printer. So, here's an ugly fallback implementation that can be
# used unconditionally to implement __repr__ in terms of _pretty_repr_.
#
# Pretty printer docs:
#   http://ipython.org/ipython-doc/dev/api/generated/IPython.lib.pretty.html 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:37,代码来源:util.py

示例9: pretty

# 需要导入模块: from IPython.lib import pretty [as 别名]
# 或者: from IPython.lib.pretty import pretty [as 别名]
def pretty(self, obj):
        if hasattr(obj, "_repr_pretty_"):
            obj._repr_pretty_(self, False)
        else:
            self.text(repr(obj)) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:7,代码来源:util.py

示例10: _mini_pretty

# 需要导入模块: from IPython.lib import pretty [as 别名]
# 或者: from IPython.lib.pretty import pretty [as 别名]
def _mini_pretty(obj):
   printer = _MiniPPrinter()
   printer.pretty(obj)
   return printer.getvalue() 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:6,代码来源:util.py

示例11: _repr_pretty_

# 需要导入模块: from IPython.lib import pretty [as 别名]
# 或者: from IPython.lib.pretty import pretty [as 别名]
def _repr_pretty_(self, p, cycle):
        if cycle:
            p.text("MyList(...)")
        else:
            with p.group(3, "MyList(", ")"):
                for (i, child) in enumerate(self.content):
                    if i:
                        p.text(",")
                        p.breakable()
                    else:
                        p.breakable("")
                    p.pretty(child) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:14,代码来源:test_pretty.py

示例12: test_indentation

# 需要导入模块: from IPython.lib import pretty [as 别名]
# 或者: from IPython.lib.pretty import pretty [as 别名]
def test_indentation():
    """Test correct indentation in groups"""
    count = 40
    gotoutput = pretty.pretty(MyList(range(count)))
    expectedoutput = "MyList(\n" + ",\n".join("   %d" % i for i in range(count)) + ")"

    nt.assert_equal(gotoutput, expectedoutput) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:9,代码来源:test_pretty.py

示例13: test_dispatch

# 需要导入模块: from IPython.lib import pretty [as 别名]
# 或者: from IPython.lib.pretty import pretty [as 别名]
def test_dispatch():
    """
    Test correct dispatching: The _repr_pretty_ method for MyDict
    must be found before the registered printer for dict.
    """
    gotoutput = pretty.pretty(MyDict())
    expectedoutput = "MyDict(...)"

    nt.assert_equal(gotoutput, expectedoutput) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:11,代码来源:test_pretty.py

示例14: test_callability_checking

# 需要导入模块: from IPython.lib import pretty [as 别名]
# 或者: from IPython.lib.pretty import pretty [as 别名]
def test_callability_checking():
    """
    Test that the _repr_pretty_ method is tested for callability and skipped if
    not.
    """
    gotoutput = pretty.pretty(Dummy2())
    expectedoutput = "Dummy1(...)"

    nt.assert_equal(gotoutput, expectedoutput) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:11,代码来源:test_pretty.py

示例15: test_sets

# 需要导入模块: from IPython.lib import pretty [as 别名]
# 或者: from IPython.lib.pretty import pretty [as 别名]
def test_sets():
    """
    Test that set and frozenset use Python 3 formatting.
    """
    objects = [set(), frozenset(), set([1]), frozenset([1]), set([1, 2]),
        frozenset([1, 2]), set([-1, -2, -3])]
    expected = ['set()', 'frozenset()', '{1}', 'frozenset({1})', '{1, 2}',
        'frozenset({1, 2})', '{-3, -2, -1}']
    for obj, expected_output in zip(objects, expected):
        got_output = pretty.pretty(obj)
        yield nt.assert_equal, got_output, expected_output 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:13,代码来源:test_pretty.py


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