當前位置: 首頁>>代碼示例>>Python>>正文


Python types.SliceType方法代碼示例

本文整理匯總了Python中types.SliceType方法的典型用法代碼示例。如果您正苦於以下問題:Python types.SliceType方法的具體用法?Python types.SliceType怎麽用?Python types.SliceType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在types的用法示例。


在下文中一共展示了types.SliceType方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __getitem__

# 需要導入模塊: import types [as 別名]
# 或者: from types import SliceType [as 別名]
def __getitem__(self, key):
        """
        Allows slicing. Returns an OrderedDict if you slice.
        >>> b = OrderedDict([(7, 0), (6, 1), (5, 2), (4, 3), (3, 4), (2, 5), (1, 6)])
        >>> b[::-1]
        OrderedDict([(1, 6), (2, 5), (3, 4), (4, 3), (5, 2), (6, 1), (7, 0)])
        >>> b[2:5]
        OrderedDict([(5, 2), (4, 3), (3, 4)])
        >>> type(b[2:4])
        <class '__main__.OrderedDict'>
        """
        if isinstance(key, types.SliceType):
            # FIXME: does this raise the error we want?
            keys = self._sequence[key]
            # FIXME: efficiency?
            return OrderedDict([(entry, self[entry]) for entry in keys])
        else:
            return dict.__getitem__(self, key) 
開發者ID:vulscanteam,項目名稱:vulscan,代碼行數:20,代碼來源:odict.py

示例2: __setitem__

# 需要導入模塊: import types [as 別名]
# 或者: from types import SliceType [as 別名]
def __setitem__(self, index, value):
        """
        Set the value at position i to value.

        You can only do slice assignment to values if you supply a sequence of
        equal length to the slice you are replacing.
        """
        if isinstance(index, types.SliceType):
            keys = self._main._sequence[index]
            if len(keys) != len(value):
                raise ValueError('attempt to assign sequence of size %s '
                    'to slice of size %s' % (len(name), len(keys)))
            # FIXME: efficiency?  Would be better to calculate the indexes
            #   directly from the slice object
            # NOTE: the new keys can collide with existing keys (or even
            #   contain duplicates) - these will overwrite
            for key, val in zip(keys, value):
                self._main[key] = val
        else:
            self._main[self._main._sequence[index]] = value

    ### following methods pinched from UserList and adapted ### 
開發者ID:vulscanteam,項目名稱:vulscan,代碼行數:24,代碼來源:odict.py

示例3: __delitem__

# 需要導入模塊: import types [as 別名]
# 或者: from types import SliceType [as 別名]
def __delitem__(self, key):
        """
        >>> d = OrderedDict(((1, 3), (3, 2), (2, 1)))
        >>> del d[3]
        >>> d
        OrderedDict([(1, 3), (2, 1)])
        >>> del d[3]
        Traceback (most recent call last):
        KeyError: 3
        >>> d[3] = 2
        >>> d
        OrderedDict([(1, 3), (2, 1), (3, 2)])
        >>> del d[0:1]
        >>> d
        OrderedDict([(2, 1), (3, 2)])
        """
        if isinstance(key, types.SliceType):
            # FIXME: efficiency?
            keys = self._sequence[key]
            for entry in keys:
                dict.__delitem__(self, entry)
            del self._sequence[key]
        else:
            # do the dict.__delitem__ *first* as it raises
            # the more appropriate error
            dict.__delitem__(self, key)
            self._sequence.remove(key) 
開發者ID:vulscanteam,項目名稱:vulscan,代碼行數:29,代碼來源:odict.py

示例4: _isFullSlice

# 需要導入模塊: import types [as 別名]
# 或者: from types import SliceType [as 別名]
def _isFullSlice(x): return type(x) == types.SliceType and x == slice(None) # the first check is necessary to avoid returning a broadcast array of False's if x is an array 
開發者ID:renmengye,項目名稱:imageqa-public,代碼行數:3,代碼來源:gnumpy.py

示例5: __getitem__

# 需要導入模塊: import types [as 別名]
# 或者: from types import SliceType [as 別名]
def __getitem__(self, i):
        if isinstance(i, types.SliceType):
            assert i.step in (None, 1),  'cannot handle slice with stride'
            return self.__class__(self.data[i.start:i.stop],
                                  items=self.items[i.start:i.stop],
                                  parent=self, parent_offset=i.start or 0)
        else:
            return self.data[i] 
開發者ID:skarlekar,項目名稱:faces,代碼行數:10,代碼來源:statemachine.py

示例6: __setitem__

# 需要導入模塊: import types [as 別名]
# 或者: from types import SliceType [as 別名]
def __setitem__(self, i, item):
        if isinstance(i, types.SliceType):
            assert i.step in (None, 1), 'cannot handle slice with stride'
            if not isinstance(item, ViewList):
                raise TypeError('assigning non-ViewList to ViewList slice')
            self.data[i.start:i.stop] = item.data
            self.items[i.start:i.stop] = item.items
            assert len(self.data) == len(self.items), 'data mismatch'
            if self.parent:
                self.parent[(i.start or 0) + self.parent_offset
                            : (i.stop or len(self)) + self.parent_offset] = item
        else:
            self.data[i] = item
            if self.parent:
                self.parent[i + self.parent_offset] = item 
開發者ID:skarlekar,項目名稱:faces,代碼行數:17,代碼來源:statemachine.py

示例7: __getitem__

# 需要導入模塊: import types [as 別名]
# 或者: from types import SliceType [as 別名]
def __getitem__(self, key):
        if isinstance(key, basestring):
            return self.attributes[key]
        elif isinstance(key, int):
            return self.children[key]
        elif isinstance(key, types.SliceType):
            assert key.step in (None, 1), 'cannot handle slice with stride'
            return self.children[key.start:key.stop]
        else:
            raise TypeError, ('element index must be an integer, a slice, or '
                              'an attribute name string') 
開發者ID:skarlekar,項目名稱:faces,代碼行數:13,代碼來源:nodes.py

示例8: __setitem__

# 需要導入模塊: import types [as 別名]
# 或者: from types import SliceType [as 別名]
def __setitem__(self, key, item):
        if isinstance(key, basestring):
            self.attributes[str(key)] = item
        elif isinstance(key, int):
            self.setup_child(item)
            self.children[key] = item
        elif isinstance(key, types.SliceType):
            assert key.step in (None, 1), 'cannot handle slice with stride'
            for node in item:
                self.setup_child(node)
            self.children[key.start:key.stop] = item
        else:
            raise TypeError, ('element index must be an integer, a slice, or '
                              'an attribute name string') 
開發者ID:skarlekar,項目名稱:faces,代碼行數:16,代碼來源:nodes.py

示例9: __delitem__

# 需要導入模塊: import types [as 別名]
# 或者: from types import SliceType [as 別名]
def __delitem__(self, key):
        if isinstance(key, basestring):
            del self.attributes[key]
        elif isinstance(key, int):
            del self.children[key]
        elif isinstance(key, types.SliceType):
            assert key.step in (None, 1), 'cannot handle slice with stride'
            del self.children[key.start:key.stop]
        else:
            raise TypeError, ('element index must be an integer, a simple '
                              'slice, or an attribute name string') 
開發者ID:skarlekar,項目名稱:faces,代碼行數:13,代碼來源:nodes.py


注:本文中的types.SliceType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。