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


Python array.__reversed__方法代码示例

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


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

示例1: BitSequence

# 需要导入模块: from array import array [as 别名]
# 或者: from array.array import __reversed__ [as 别名]

#.........这里部分代码省略.........

    def _init_from_iterable(self, iterable, msb):
        """Initialize from an iterable"""
        smap = { '0': 0, '1': 1, False: 0, True: 1, 0: 0, 1: 1 }
        seq = self._seq
        try:
            if msb:
                seq.extend([smap[bit] for bit in reversed(iterable)])
            else:
                seq.extend([smap[bit] for bit in iterable])
        except KeyError:
            raise BitSequenceError("Invalid binary character in initializer")

    def _init_from_sibling(self, value, msb):
        """Initialize from a fellow object"""
        self._seq = value.sequence()
        if msb:
            self._seq.reverse()

    def _update_length(self, length, msb):
        """If a specific length is specified, extend the sequence as
           expected"""
        if length and (len(self) < length):
            extra = Array('B', [False] * (length-len(self)))
            if msb:
                extra.extend(self._seq)
                self._seq = extra
            else:
                self._seq.extend(extra)

    def __iter__(self):
        return self._seq.__iter__()

    def __reversed__(self):
        return self._seq.__reversed__()

    def __getitem__(self, index):
        if isinstance(index, slice):
            return self.__class__(value=self._seq[index])
        else:
            return self._seq[index]

    def __setitem__(self, index, value):
        if isinstance(value, BitSequence):
            if issubclass(value.__class__, self.__class__) and \
               value.__class__ != self.__class__:
                raise BitSequenceError("Cannot set item with instance of a "
                                       "subclass")
        if isinstance(index, slice):
            value = self.__class__(value, length=len(self._seq[index]))
            self._seq[index] = value.sequence()
        else:
            if not isinstance(value, BitSequence):
                value = self.__class__(value)
            val = value.tobit()
            if index > len(self._seq):
                raise BitSequenceError("Cannot change the sequence size")
            self._seq[index] = val

    def __len__(self):
        return len(self._seq)

    def __cmp__(self, other):
        # the bit sequence should be of the same length
        ld = len(self) - len(other)
        if ld:
开发者ID:adamfeuer,项目名称:pyftdi,代码行数:70,代码来源:bits.py


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