當前位置: 首頁>>代碼示例>>Python>>正文


Python pprint.html方法代碼示例

本文整理匯總了Python中pprint.html方法的典型用法代碼示例。如果您正苦於以下問題:Python pprint.html方法的具體用法?Python pprint.html怎麽用?Python pprint.html使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pprint的用法示例。


在下文中一共展示了pprint.html方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _ustr

# 需要導入模塊: import pprint [as 別名]
# 或者: from pprint import html [as 別名]
def _ustr(obj):
        """Drop-in replacement for str(obj) that tries to be Unicode friendly. It first tries
           str(obj). If that fails with a UnicodeEncodeError, then it tries unicode(obj). It
           then < returns the unicode object | encodes it with the default encoding | ... >.
        """
        if isinstance(obj,unicode):
            return obj

        try:
            # If this works, then _ustr(obj) has the same behaviour as str(obj), so
            # it won't break any existing code.
            return str(obj)

        except UnicodeEncodeError:
            # The Python docs (http://docs.python.org/ref/customization.html#l2h-182)
            # state that "The return value must be a string object". However, does a
            # unicode object (being a subclass of basestring) count as a "string
            # object"?
            # If so, then return a unicode object:
            return unicode(obj)
            # Else encode it... but how? There are many choices... :)
            # Replace unprintables with escape codes?
            #return unicode(obj).encode(sys.getdefaultencoding(), 'backslashreplace_errors')
            # Replace unprintables with question marks?
            #return unicode(obj).encode(sys.getdefaultencoding(), 'replace')
            # ...

    # build list of single arg builtins, tolerant of Python version, that can be used as parse actions 
開發者ID:vulscanteam,項目名稱:vulscan,代碼行數:30,代碼來源:pyparsing.py

示例2: pprint

# 需要導入模塊: import pprint [as 別名]
# 或者: from pprint import html [as 別名]
def pprint(self, *args, **kwargs):
        """Pretty-printer for parsed results as a list, using the C{pprint} module.
           Accepts additional positional or keyword args as defined for the 
           C{pprint.pprint} method. (U{http://docs.python.org/3/library/pprint.html#pprint.pprint})"""
        pprint.pprint(self.asList(), *args, **kwargs)

    # add support for pickle protocol 
開發者ID:vulscanteam,項目名稱:vulscan,代碼行數:9,代碼來源:pyparsing.py

示例3: _ustr

# 需要導入模塊: import pprint [as 別名]
# 或者: from pprint import html [as 別名]
def _ustr(obj):
        """Drop-in replacement for str(obj) that tries to be Unicode friendly. It first tries
           str(obj). If that fails with a UnicodeEncodeError, then it tries unicode(obj). It
           then < returns the unicode object | encodes it with the default encoding | ... >.
        """
        if isinstance(obj, unicode):
            return obj

        try:
            # If this works, then _ustr(obj) has the same behaviour as str(obj), so
            # it won't break any existing code.
            return str(obj)

        except UnicodeEncodeError:
            # The Python docs (http://docs.python.org/ref/customization.html#l2h-182)
            # state that "The return value must be a string object". However, does a
            # unicode object (being a subclass of basestring) count as a "string
            # object"?
            # If so, then return a unicode object:
            return unicode(obj)
            # Else encode it... but how? There are many choices... :)
            # Replace unprintables with escape codes?
            #return unicode(obj).encode(sys.getdefaultencoding(), 'backslashreplace_errors')
            # Replace unprintables with question marks?
            #return unicode(obj).encode(sys.getdefaultencoding(), 'replace')
            # ...

    # build list of single arg builtins, tolerant of Python version, that can be used as parse actions 
開發者ID:DavexPro,項目名稱:PocHunter,代碼行數:30,代碼來源:pyparsing.py

示例4: pyparsing_parseresults_pformat

# 需要導入模塊: import pprint [as 別名]
# 或者: from pprint import html [as 別名]
def pyparsing_parseresults_pformat(self, *args, **kwargs):
    """
    Pretty-print formatter for parsed results as a list, using the C{pprint} module.
    Accepts additional positional or keyword args as defined for the
    C{pprint.pformat} method. (U{http://docs.python.org/3/library/pprint.html#pprint.pformat})
    """
    return pprint.pformat(self.asList(), *args, **kwargs) 
開發者ID:ip-tools,項目名稱:patzilla,代碼行數:9,代碼來源:__init__.py

示例5: pprint

# 需要導入模塊: import pprint [as 別名]
# 或者: from pprint import html [as 別名]
def pprint(self, *args, **kwargs):
        """
        Pretty-printer for parsed results as a list, using the
        `pprint <https://docs.python.org/3/library/pprint.html>`_ module.
        Accepts additional positional or keyword args as defined for
        `pprint.pprint <https://docs.python.org/3/library/pprint.html#pprint.pprint>`_ .

        Example::

            ident = Word(alphas, alphanums)
            num = Word(nums)
            func = Forward()
            term = ident | num | Group('(' + func + ')')
            func <<= ident + Group(Optional(delimitedList(term)))
            result = func.parseString("fna a,b,(fnb c,d,200),100")
            result.pprint(width=40)

        prints::

            ['fna',
             ['a',
              'b',
              ['(', 'fnb', ['c', 'd', '200'], ')'],
              '100']]
        """
        pprint.pprint(self.asList(), *args, **kwargs)

    # add support for pickle protocol 
開發者ID:pyparsing,項目名稱:pyparsing,代碼行數:30,代碼來源:results.py


注:本文中的pprint.html方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。