本文整理汇总了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: