本文整理汇总了Python中collections.Sequence类的典型用法代码示例。如果您正苦于以下问题:Python Sequence类的具体用法?Python Sequence怎么用?Python Sequence使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Sequence类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, lstFn):
"""Construct a new CachedList. The lstFn is a function that takes
no parameters and returns a list. It will be called lazily - the
list is not constructed until the first access, which could be
quite a while after this method is called."""
Sequence.__init__(self)
self._invalid = True
self._lst = []
self._lstFn = lstFn
示例2: count
else:
return self._xrange[index]
def count(self, elem):
"""Count the number of times elem appears in the range."""
return int(elem in self._xrange)
def index(self, elem):
"""Find the index of elem in the range."""
if elem not in self._xrange: raise _coconut.ValueError(_coconut.repr(elem) + " is not in range")
start, _, step = self._xrange.__reduce_ex__(2)[1]
return (elem - start) // step
def __repr__(self):
return _coconut.repr(self._xrange)[1:]
def __reduce_ex__(self, protocol):
return (self.__class__, self._xrange.__reduce_ex__(protocol)[1])
from collections import Sequence as _coconut_Sequence
_coconut_Sequence.register(range)
class int(_coconut_int):
__slots__ = ()
__doc__ = _coconut_int.__doc__
class __metaclass__(type):
def __instancecheck__(cls, inst):
return _coconut.isinstance(inst, (_coconut_int, _coconut_long))
class bytes(_coconut_str):
__slots__ = ()
__doc__ = _coconut_str.__doc__
class __metaclass__(type):
def __instancecheck__(cls, inst):
return _coconut.isinstance(inst, _coconut_str)
def __new__(cls, *args, **kwargs):
return _coconut_str.__new__(cls, _coconut.bytearray(*args, **kwargs))
def print(*args, **kwargs):
示例3: __init__
def __init__(self, traces):
Sequence.__init__(self)
self._traces = traces
示例4: plist
plist([3, 1])
"""
__slots__ = ('first', 'rest')
def __new__(cls, first, rest):
instance = super(PList, cls).__new__(cls)
instance.first = first
instance.rest = rest
return instance
def __bool__(self):
return True
__nonzero__ = __bool__
Sequence.register(PList)
Hashable.register(PList)
class _EmptyPList(_PListBase):
__slots__ = ()
def __bool__(self):
return False
__nonzero__ = __bool__
@property
def first(self):
raise AttributeError("Empty PList has no first")
@property
示例5: __len__
def __len__(self):
return self._len()
def __contains__(self, item):
return item in self.data
def __reversed__(self):
return reversed(self.data)
def __getitem__(self, index):
return self.data[index]
@property
def _evictcount(self):
return len(self)
Sequence.register(Messagebuffer)
@python_2_unicode_compatible
class BufferMapping(OrderedDict, Evictable):
Buffer = Messagebuffer
Empty = Empty
maxsize = None
total = 0
bufmaxsize = None
def __init__(self, maxsize, iterable=None, bufmaxsize=1000):
super(BufferMapping, self).__init__()
self.maxsize = maxsize
示例6: iterkeys
return self._parent.keys
def iterkeys(self):
return iter(self._parent.keys)
def itervalues(self):
return iter(self)
try:
# Register RowProxy with Sequence,
# so sequence protocol is implemented
from collections import Sequence
Sequence.register(RowProxy)
except ImportError:
pass
class ResultMetaData(object):
"""Handle cursor.description, applying additional info from an execution
context."""
def __init__(self, parent, metadata):
context = parent.context
dialect = context.dialect
typemap = dialect.dbapi_type_map
translate_colname = context._translate_colname
self.case_sensitive = case_sensitive = dialect.case_sensitive
示例7: __reversed__
def __reversed__(self):
# type: () -> Iterable
return reversed(self.data)
def __getitem__(self, index):
# type: (Any) -> Any
return self.data[index]
@property
def _evictcount(self):
# type: () -> int
return len(self)
Sequence.register(Messagebuffer) # noqa: E305
@python_2_unicode_compatible
class BufferMap(OrderedDict, Evictable):
"""Map of buffers."""
Buffer = Messagebuffer
Empty = Empty
maxsize = None
total = 0
bufmaxsize = None
def __init__(self, maxsize, iterable=None, bufmaxsize=1000):
# type: (int, Iterable, int) -> None
示例8: __init__
def __init__(self, attribs=None):
Sequence.__init__(self)
self.descriptors = list(attribs or [])
示例9: delete
@abstractmethod
def delete(self, index, stop=None):
"""
Delete a portion of the vector by index or range.
>>> v1 = v(1, 2, 3, 4, 5)
>>> v1.delete(1)
pvector([1, 3, 4, 5])
>>> v1.delete(1, 3)
pvector([1, 4, 5])
"""
_EMPTY_PVECTOR = PythonPVector(0, SHIFT, [], [])
PVector.register(PythonPVector)
Sequence.register(PVector)
Hashable.register(PVector)
def python_pvector(iterable=()):
"""
Create a new persistent vector containing the elements in iterable.
>>> v1 = pvector([1, 2, 3])
>>> v1
pvector([1, 2, 3])
"""
return _EMPTY_PVECTOR.extend(iterable)
try:
# Use the C extension as underlying trie implementation if it is available
import os
示例10: _intervals
represent non-overlapping intervals such that for any start <= x < end
x in self
"""
return _intervals(self.wrapped)
def reversed_intervals(self):
"""Iterator over the reverse of intervals()"""
return _reversed_intervals(self.wrapped)
def __reversed__(self):
for start, end in self.reversed_intervals():
for i in range(end - 1, start - 1, -1):
yield i
Sequence.register(IntSet)
Set.register(IntSet)
def _new_maybe_empty_interval(start, end):
if end <= start:
return ()
return _new_interval(start, end)
_START = 0
_END = 1
_SIZE = 2
_PREFIX = 3
_MASK = 4
_LEFT = 5
示例11: isinstance
if index.stop is not None:
result = result.pop(self._length - (index.stop % self._length))
return result
if not isinstance(index, Integral):
raise TypeError("'%s' object cannot be interpreted as an index" % type(index).__name__)
if index >= 0:
return self.popleft(index).left
return self.pop(index).right
index = Sequence.index
Sequence.register(PDeque)
Hashable.register(PDeque)
def pdeque(iterable=(), maxlen=None):
"""
Return deque containing the elements of iterable. If maxlen is specified then
len(iterable) - maxlen elements are discarded from the left to if len(iterable) > maxlen.
>>> pdeque([1, 2, 3])
pdeque([1, 2, 3])
>>> pdeque([1, 2, 3, 4], maxlen=2)
pdeque([3, 4], maxlen=2)
"""
t = tuple(iterable)
if maxlen is not None: