Python collections.OrderedDict 模块,__repr__() 实例源码

我们从Python开源项目中,提取了以下10个代码示例,用于说明如何使用collections.OrderedDict.__repr__()

项目:ssbio    作者:SBRG    | 项目源码 | 文件源码
def __repr__(self):
        return 'OrderedDefaultDict(%s, %s)' % (self.default_factory,
                                               OrderedDict.__repr__(self))
项目:python-zhmcclient    作者:zhmcclient    | 项目源码 | 文件源码
def pprint_for_ordereddict():
    """
    Context manager that causes pprint() to print OrderedDict objects as nicely
    as standard Python dictionary objects.
    """
    od_saved = OrderedDict.__repr__
    try:
        OrderedDict.__repr__ = dict.__repr__
        yield
    finally:
        OrderedDict.__repr__ = od_saved
项目:Comparative-Annotation-Toolkit    作者:ComparativeGenomicsToolkit    | 项目源码 | 文件源码
def __repr__(self):
        return 'OrderedDefaultDict(%s, %s)' % (self.default_factory,
                                               OrderedDict.__repr__(self))
项目:mappyfile    作者:geographika    | 项目源码 | 文件源码
def __repr__(self):
        return 'DefaultOrderedDict(%s, %s)' % (self.default_factory,
                                               OrderedDict.__repr__(self))
项目:plumeria    作者:sk89q    | 项目源码 | 文件源码
def __repr__(self, *args, **kwargs):
        return self.o.__repr__(*args, **kwargs)
项目:plumeria    作者:sk89q    | 项目源码 | 文件源码
def __repr__(self):
        return 'OrderedDefaultDict(%s, %s)' % (self.default_factory,
                                               OrderedDict.__repr__(self))


# From requests (Apache 2 License)
项目:plumeria    作者:sk89q    | 项目源码 | 文件源码
def __repr__(self):
        return str(dict(self.items()))


# From requests (Apache 2 License)
项目:plumeria    作者:sk89q    | 项目源码 | 文件源码
def __repr__(self):
        return '<lookup \'%s\'>' % (self.name)
项目:PyTib    作者:Esukhia    | 项目源码 | 文件源码
def __repr__(self):
        return 'OrderedDefaultDict(%s, %s)' % (self.default_factory, OrderedDict.__repr__(self))
项目:python-zeep    作者:mvantellingen    | 项目源码 | 文件源码
def _format(self, obj, stream, indent=4, level=1):
        _repr = getattr(type(obj), '__repr__', None)
        write = stream.write

        if (
            (isinstance(obj, dict) and _repr is dict.__repr__) or
            (isinstance(obj, OrderedDict) and _repr == OrderedDict.__repr__)
        ):
            write('{\n')
            num = len(obj)

            if num > 0:
                for i, (key, value) in enumerate(obj.items()):
                    write(' ' * (indent * level))
                    write("'%s'" % key)
                    write(': ')
                    self._format(value, stream, level=level + 1)
                    if i < num - 1:
                        write(',')
                    write('\n')

                write(' ' * (indent * (level - 1)))
            write('}')

        elif isinstance(obj, list) and _repr is list.__repr__:
            write('[')
            num = len(obj)

            if num > 0:
                write('\n')
                for i, value in enumerate(obj):
                    write(' ' * (indent * level))
                    self._format(value, stream, level=level + 1)
                    if i < num - 1:
                        write(',')
                    write('\n')
                write(' ' * (indent * (level - 1)))
            write(']')
        else:
            value = repr(obj)
            if '\n' in value:
                lines = value.split('\n')
                num = len(lines)
                for i, line in enumerate(lines):
                    if i > 0:
                        write(' ' * (indent * (level - 1)))
                    write(line)
                    if i < num - 1:
                        write('\n')
            else:
                write(value)