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


Python builtins.repr方法代碼示例

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


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

示例1: recursive_repr

# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import repr [as 別名]
def recursive_repr(fillvalue='...'):
    'Decorator to make a repr function return fillvalue for a recursive call'

    def decorating_function(user_function):
        repr_running = set()

        def wrapper(self):
            key = id(self), get_ident()
            if key in repr_running:
                return fillvalue
            repr_running.add(key)
            try:
                result = user_function(self)
            finally:
                repr_running.discard(key)
            return result

        # Can't use functools.wraps() here because of bootstrap issues
        wrapper.__module__ = getattr(user_function, '__module__')
        wrapper.__doc__ = getattr(user_function, '__doc__')
        wrapper.__name__ = getattr(user_function, '__name__')
        wrapper.__annotations__ = getattr(user_function, '__annotations__', {})
        return wrapper

    return decorating_function 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:27,代碼來源:reprlib.py

示例2: repr

# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import repr [as 別名]
def repr(self, x):
        return self.repr1(x, self.maxlevel) 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:4,代碼來源:reprlib.py

示例3: repr_str

# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import repr [as 別名]
def repr_str(self, x, level):
        s = builtins.repr(x[:self.maxstring])
        if len(s) > self.maxstring:
            i = max(0, (self.maxstring-3)//2)
            j = max(0, self.maxstring-3-i)
            s = builtins.repr(x[:i] + x[len(x)-j:])
            s = s[:i] + '...' + s[len(s)-j:]
        return s 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:10,代碼來源:reprlib.py

示例4: repr_int

# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import repr [as 別名]
def repr_int(self, x, level):
        s = builtins.repr(x) # XXX Hope this isn't too slow...
        if len(s) > self.maxlong:
            i = max(0, (self.maxlong-3)//2)
            j = max(0, self.maxlong-3-i)
            s = s[:i] + '...' + s[len(s)-j:]
        return s 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:9,代碼來源:reprlib.py

示例5: repr_instance

# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import repr [as 別名]
def repr_instance(self, x, level):
        try:
            s = builtins.repr(x)
            # Bugs in x.__repr__() can cause arbitrary
            # exceptions -- then make up something
        except Exception:
            return '<%s instance at %x>' % (x.__class__.__name__, id(x))
        if len(s) > self.maxother:
            i = max(0, (self.maxother-3)//2)
            j = max(0, self.maxother-3-i)
            s = s[:i] + '...' + s[len(s)-j:]
        return s 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:14,代碼來源:reprlib.py

示例6: recursive_repr

# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import repr [as 別名]
def recursive_repr(fillvalue='...'):
    'Decorator to make a repr function return fillvalue for a recursive call'

    def decorating_function(user_function):
        repr_running = set()

        def wrapper(self):
            key = id(self), get_ident()
            if key in repr_running:
                return fillvalue
            repr_running.add(key)
            try:
                result = user_function(self)
            finally:
                repr_running.discard(key)
            return result

        # Can't use functools.wraps() here because of bootstrap issues
        wrapper.__module__ = getattr(user_function, '__module__')
        wrapper.__doc__ = getattr(user_function, '__doc__')
        wrapper.__name__ = getattr(user_function, '__name__')
        wrapper.__qualname__ = getattr(user_function, '__qualname__')
        wrapper.__annotations__ = getattr(user_function, '__annotations__', {})
        return wrapper

    return decorating_function 
開發者ID:awemulya,項目名稱:kobo-predict,代碼行數:28,代碼來源:reprlib.py

示例7: repr_instance

# 需要導入模塊: import builtins [as 別名]
# 或者: from builtins import repr [as 別名]
def repr_instance(self, x, level):
        try:
            s = builtins.repr(x)
            # Bugs in x.__repr__() can cause arbitrary
            # exceptions -- then make up something
        except Exception:
            return '<%s instance at %#x>' % (x.__class__.__name__, id(x))
        if len(s) > self.maxother:
            i = max(0, (self.maxother-3)//2)
            j = max(0, self.maxother-3-i)
            s = s[:i] + '...' + s[len(s)-j:]
        return s 
開發者ID:awemulya,項目名稱:kobo-predict,代碼行數:14,代碼來源:reprlib.py


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