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


Python __builtin__.repr方法代码示例

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


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

示例1: recursive_repr

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ 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:remg427,项目名称:misp42splunk,代码行数:27,代码来源:reprlib32.py

示例2: repr

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import repr [as 别名]
def repr(self, x):
        return self.repr1(x, self.maxlevel) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:4,代码来源:reprlib32.py

示例3: repr_str

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ 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:remg427,项目名称:misp42splunk,代码行数:10,代码来源:reprlib32.py

示例4: repr_int

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ 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:remg427,项目名称:misp42splunk,代码行数:9,代码来源:reprlib32.py

示例5: repr_instance

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ 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:remg427,项目名称:misp42splunk,代码行数:14,代码来源:reprlib32.py

示例6: repr1

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import repr [as 别名]
def repr1(self, x, level):
        typename = type(x).__name__
        if ' ' in typename:
            parts = typename.split()
            typename = '_'.join(parts)
        if hasattr(self, 'repr_' + typename):
            return getattr(self, 'repr_' + typename)(x, level)
        else:
            s = __builtin__.repr(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:glmcdona,项目名称:meddle,代码行数:16,代码来源:repr.py

示例7: repr_str

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import repr [as 别名]
def repr_str(self, x, level):
        s = __builtin__.repr(x[:self.maxstring])
        if len(s) > self.maxstring:
            i = max(0, (self.maxstring-3)//2)
            j = max(0, self.maxstring-3-i)
            s = __builtin__.repr(x[:i] + x[len(x)-j:])
            s = s[:i] + '...' + s[len(s)-j:]
        return s 
开发者ID:glmcdona,项目名称:meddle,代码行数:10,代码来源:repr.py

示例8: repr_long

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import repr [as 别名]
def repr_long(self, x, level):
        s = __builtin__.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:glmcdona,项目名称:meddle,代码行数:9,代码来源:repr.py

示例9: repr_instance

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import repr [as 别名]
def repr_instance(self, x, level):
        try:
            s = __builtin__.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.maxstring:
            i = max(0, (self.maxstring-3)//2)
            j = max(0, self.maxstring-3-i)
            s = s[:i] + '...' + s[len(s)-j:]
        return s 
开发者ID:glmcdona,项目名称:meddle,代码行数:14,代码来源:repr.py


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