Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(2)  |  Call(1)  |  Derive(0)  |  Import(1)

        def ppformat(obj):
    '''Just like :func:`pprint` but always returns the result instead of
    writing it to a stream.

    :returns: The pretty formated text.
    :rtype: `unicode` in Python 2, `str` in Python 3.

    '''
    import io
    from xoutil.six import PY3, text_type
    if PY3:
        stream = io.StringIO()
    else:
        stream = io.BytesIO()
    pprint(obj, stream=stream)
    stream.seek(0)
    res = stream.read()
    if isinstance(res, text_type):
        return res
    else:
        from xoutil.string import safe_decode
        return safe_decode(res)
        


src/x/o/xoutil-1.5.4/tests/test_pprint.py   xoutil(Download)
def test_ppformat_rtype():
    from xoutil.pprint import ppformat
    from xoutil.six import text_type
    o = [list(range(i+1)) for i in range(10)]
    assert type(ppformat(o)) is text_type