python类values()的实例源码

odict.py 文件源码 项目:autoinjection 作者: ChengWiLL 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def setvalues(self, values):
        """
        You can pass in a list of values, which will replace the
        current list. The value list must be the same len as the OrderedDict.

        (Or a ``ValueError`` is raised.)

        >>> d = OrderedDict(((1, 3), (3, 2), (2, 1)))
        >>> d.setvalues((1, 2, 3))
        >>> d
        OrderedDict([(1, 1), (3, 2), (2, 3)])
        >>> d.setvalues([6])
        Traceback (most recent call last):
        ValueError: Value list is not the same length as the OrderedDict.
        """
        if len(values) != len(self):
            # FIXME: correct error to raise?
            raise ValueError('Value list is not the same length as the '
                'OrderedDict.')
        self.update(zip(self, values))

### Sequence Methods ###
odict.py 文件源码 项目:PocHunter 作者: DavexPro 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def setvalues(self, values):
        """
        You can pass in a list of values, which will replace the
        current list. The value list must be the same len as the OrderedDict.

        (Or a ``ValueError`` is raised.)

        >>> d = OrderedDict(((1, 3), (3, 2), (2, 1)))
        >>> d.setvalues((1, 2, 3))
        >>> d
        OrderedDict([(1, 1), (3, 2), (2, 3)])
        >>> d.setvalues([6])
        Traceback (most recent call last):
        ValueError: Value list is not the same length as the OrderedDict.
        """
        if len(values) != len(self):
            # FIXME: correct error to raise?
            raise ValueError('Value list is not the same length as the '
                'OrderedDict.')
        self.update(zip(self, values))

### Sequence Methods ###
odict.py 文件源码 项目:Eagle 作者: magerx 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def setvalues(self, values):
        """
        You can pass in a list of values, which will replace the
        current list. The value list must be the same len as the OrderedDict.

        (Or a ``ValueError`` is raised.)

        >>> d = OrderedDict(((1, 3), (3, 2), (2, 1)))
        >>> d.setvalues((1, 2, 3))
        >>> d
        OrderedDict([(1, 1), (3, 2), (2, 3)])
        >>> d.setvalues([6])
        Traceback (most recent call last):
        ValueError: Value list is not the same length as the OrderedDict.
        """
        if len(values) != len(self):
            # FIXME: correct error to raise?
            raise ValueError('Value list is not the same length as the '
                'OrderedDict.')
        self.update(zip(self, values))

### Sequence Methods ###
odict.py 文件源码 项目:Helix 作者: 3lackrush 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def setvalues(self, values):
        """
        You can pass in a list of values, which will replace the
        current list. The value list must be the same len as the OrderedDict.

        (Or a ``ValueError`` is raised.)

        >>> d = OrderedDict(((1, 3), (3, 2), (2, 1)))
        >>> d.setvalues((1, 2, 3))
        >>> d
        OrderedDict([(1, 1), (3, 2), (2, 3)])
        >>> d.setvalues([6])
        Traceback (most recent call last):
        ValueError: Value list is not the same length as the OrderedDict.
        """
        if len(values) != len(self):
            # FIXME: correct error to raise?
            raise ValueError('Value list is not the same length as the '
                'OrderedDict.')
        self.update(zip(self, values))

### Sequence Methods ###
odict.py 文件源码 项目:autoscan 作者: b01u 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def setvalues(self, values):
        """
        You can pass in a list of values, which will replace the
        current list. The value list must be the same len as the OrderedDict.

        (Or a ``ValueError`` is raised.)

        >>> d = OrderedDict(((1, 3), (3, 2), (2, 1)))
        >>> d.setvalues((1, 2, 3))
        >>> d
        OrderedDict([(1, 1), (3, 2), (2, 3)])
        >>> d.setvalues([6])
        Traceback (most recent call last):
        ValueError: Value list is not the same length as the OrderedDict.
        """
        if len(values) != len(self):
            # FIXME: correct error to raise?
            raise ValueError('Value list is not the same length as the '
                'OrderedDict.')
        self.update(zip(self, values))

### Sequence Methods ###
odict.py 文件源码 项目:autoinjection 作者: ChengWiLL 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def items(self):
        """
        ``items`` returns a list of tuples representing all the 
        ``(key, value)`` pairs in the dictionary.

        >>> d = OrderedDict(((1, 3), (3, 2), (2, 1)))
        >>> d.items()
        [(1, 3), (3, 2), (2, 1)]
        >>> d.clear()
        >>> d.items()
        []
        """
        return zip(self._sequence, self.values())
odict.py 文件源码 项目:autoinjection 作者: ChengWiLL 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def values(self, values=None):
        """
        Return a list of all the values in the OrderedDict.

        Optionally you can pass in a list of values, which will replace the
        current list. The value list must be the same len as the OrderedDict.

        >>> d = OrderedDict(((1, 3), (3, 2), (2, 1)))
        >>> d.values()
        [3, 2, 1]
        """
        return [self[key] for key in self._sequence]
odict.py 文件源码 项目:autoinjection 作者: ChengWiLL 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def rename(self, old_key, new_key):
        """
        Rename the key for a given value, without modifying sequence order.

        For the case where new_key already exists this raise an exception,
        since if new_key exists, it is ambiguous as to what happens to the
        associated values, and the position of new_key in the sequence.

        >>> od = OrderedDict()
        >>> od['a'] = 1
        >>> od['b'] = 2
        >>> od.items()
        [('a', 1), ('b', 2)]
        >>> od.rename('b', 'c')
        >>> od.items()
        [('a', 1), ('c', 2)]
        >>> od.rename('c', 'a')
        Traceback (most recent call last):
        ValueError: New key already exists: 'a'
        >>> od.rename('d', 'b')
        Traceback (most recent call last):
        KeyError: 'd'
        """
        if new_key == old_key:
            # no-op
            return
        if new_key in self:
            raise ValueError("New key already exists: %r" % new_key)
        # rename sequence entry
        value = self[old_key] 
        old_idx = self._sequence.index(old_key)
        self._sequence[old_idx] = new_key
        # rename internal dict entry
        dict.__delitem__(self, old_key)
        dict.__setitem__(self, new_key, value)
odict.py 文件源码 项目:autoinjection 作者: ChengWiLL 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def __call__(self):
        """Pretend to be the values method."""
        return self._main._values()
odict.py 文件源码 项目:autoinjection 作者: ChengWiLL 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def __repr__(self): return repr(self._main.values())

    # FIXME: do we need to check if we are comparing with another ``Values``
    #   object? (like the __cast method of UserList)
odict.py 文件源码 项目:autoinjection 作者: ChengWiLL 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def __lt__(self, other): return self._main.values() <  other
odict.py 文件源码 项目:autoinjection 作者: ChengWiLL 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __le__(self, other): return self._main.values() <= other
odict.py 文件源码 项目:autoinjection 作者: ChengWiLL 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def __eq__(self, other): return self._main.values() == other
odict.py 文件源码 项目:autoinjection 作者: ChengWiLL 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def __ne__(self, other): return self._main.values() != other
odict.py 文件源码 项目:autoinjection 作者: ChengWiLL 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def __ge__(self, other): return self._main.values() >= other
odict.py 文件源码 项目:autoinjection 作者: ChengWiLL 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def __cmp__(self, other): return cmp(self._main.values(), other)
odict.py 文件源码 项目:autoinjection 作者: ChengWiLL 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def __contains__(self, item): return item in self._main.values()
odict.py 文件源码 项目:autoinjection 作者: ChengWiLL 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def count(self, item): return self._main.values().count(item)
odict.py 文件源码 项目:autoinjection 作者: ChengWiLL 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def index(self, item, *args): return self._main.values().index(item, *args)
odict.py 文件源码 项目:autoinjection 作者: ChengWiLL 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def sort(self, *args, **kwds):
        """Sort the values."""
        vals = self._main.values()
        vals.sort(*args, **kwds)
        self[:] = vals
odict.py 文件源码 项目:autoinjection 作者: ChengWiLL 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def __mul__(self, n): return self._main.values()*n
odict.py 文件源码 项目:autoinjection 作者: ChengWiLL 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def __add__(self, other): return self._main.values() + other
odict.py 文件源码 项目:autoinjection 作者: ChengWiLL 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def __radd__(self, other): return other + self._main.values()

    ## following methods not implemented for values ##
odict.py 文件源码 项目:autoinjection 作者: ChengWiLL 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __delitem__(self, i): raise TypeError('Can\'t delete items from values')
odict.py 文件源码 项目:autoinjection 作者: ChengWiLL 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def __imul__(self, n): raise TypeError('Can\'t multiply values in place')
odict.py 文件源码 项目:autoinjection 作者: ChengWiLL 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def append(self, item): raise TypeError('Can\'t append items to values')
odict.py 文件源码 项目:autoinjection 作者: ChengWiLL 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def insert(self, i, item): raise TypeError('Can\'t insert items into values')
odict.py 文件源码 项目:autoinjection 作者: ChengWiLL 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def pop(self, i=-1): raise TypeError('Can\'t pop items from values')
odict.py 文件源码 项目:autoinjection 作者: ChengWiLL 项目源码 文件源码 阅读 15 收藏 0 点赞 0 评论 0
def remove(self, item): raise TypeError('Can\'t remove items from values')
odict.py 文件源码 项目:autoinjection 作者: ChengWiLL 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def __init__(self, init_val=(), strict=True):
        OrderedDict.__init__(self, init_val, strict=strict)
        self._keys = self.keys
        self._values = self.values
        self._items = self.items
        self.keys = Keys(self)
        self.values = Values(self)
        self.items = Items(self)
        self._att_dict = {
            'keys': self.setkeys,
            'items': self.setitems,
            'values': self.setvalues,
        }


问题


面经


文章

微信
公众号

扫码关注公众号