python类__setitem__()的实例源码

__init__.py 文件源码 项目:midict 作者: ShenggaoZhu 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def __setitem__(self, item, value):
        '''
        Set one or more items using flexible indexing.

        The slice and int syntax (including int in the tuple/list syntax) can
        only be used to change values of existing keys, rather than set values
        for new keys.
        '''
        item2, single = convert_index_to_keys(self, item)
        super_setitem = super(IndexDict, self).__setitem__
        if single:
            super_setitem(item2, value)
        else:
            if len(item2) != len(value):
                raise ValueError(
                    'Number of keys (%s) based on argument %s does not match '
                    'number of values (%s)' % (len(item2), item, len(value)))
            map(IndexDict_check_key_type, item2)
            return map(super_setitem, item2, value)
pgcollections.py 文件源码 项目:NeoAnalysis 作者: neoanalysis 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def __setitem__(self, item, value):
        self.reverse[value] = item
        dict.__setitem__(self, item, value)
pgcollections.py 文件源码 项目:NeoAnalysis 作者: neoanalysis 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def __setitem__(self, item, value):
        dict.__setitem__(self, item, value)
        dict.__setitem__(self, value, item)
pgcollections.py 文件源码 项目:NeoAnalysis 作者: neoanalysis 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def __setitem__(self, attr, val):
        if type(val) is dict:
            val = ThreadsafeDict(val)
        self.lock()
        try:
            dict.__setitem__(self, attr, val)
        finally:
            self.unlock()
pgcollections.py 文件源码 项目:NeoAnalysis 作者: neoanalysis 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def __setitem__(self, attr, val):
        val = makeThreadsafe(val)
        self.lock()
        try:
            list.__setitem__(self, attr, val)
        finally:
            self.unlock()
pgcollections.py 文件源码 项目:NeoAnalysis 作者: neoanalysis 项目源码 文件源码 阅读 15 收藏 0 点赞 0 评论 0
def __setitem__(self, key, val):
        kl = key.lower()
        if kl in self.keyMap:
            OrderedDict.__setitem__(self, self.keyMap[kl], val)
        else:
            OrderedDict.__setitem__(self, key, val)
            self.keyMap[kl] = key
pgcollections.py 文件源码 项目:NeoAnalysis 作者: neoanalysis 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __setitem__(self, item, value):
        dict.__setitem__(self, item, value)
        dict.__setitem__(self, value, item)
pgcollections.py 文件源码 项目:NeoAnalysis 作者: neoanalysis 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def __setitem__(self, attr, val):
        if type(val) is dict:
            val = ThreadsafeDict(val)
        self.lock()
        try:
            dict.__setitem__(self, attr, val)
        finally:
            self.unlock()
pgcollections.py 文件源码 项目:NeoAnalysis 作者: neoanalysis 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def __setitem__(self, attr, val):
        val = makeThreadsafe(val)
        self.lock()
        try:
            list.__setitem__(self, attr, val)
        finally:
            self.unlock()
pgcollections.py 文件源码 项目:NeoAnalysis 作者: neoanalysis 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def __setitem__(self, key, val):
        kl = key.lower()
        if kl in self.keyMap:
            OrderedDict.__setitem__(self, self.keyMap[kl], val)
        else:
            OrderedDict.__setitem__(self, key, val)
            self.keyMap[kl] = key
lru_cache.py 文件源码 项目:mopidy-tidal 作者: mones88 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def __setitem__(self, key, value):
        if key in self:
            del self[key]
        OrderedDict.__setitem__(self, key, value)
        self._check_limit()
utils.py 文件源码 项目:Sublime-uroboroSQL-formatter 作者: future-architect 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def __getitem__(self, key, *args, **kwargs):
            # Get the key and remove it from the cache, or raise KeyError
            value = OrderedDict.__getitem__(self, key)
            del self[key]

            # Insert the (key, value) pair on the front of the cache
            OrderedDict.__setitem__(self, key, value)

            # Return the value from the cache
            return value
utils.py 文件源码 项目:Sublime-uroboroSQL-formatter 作者: future-architect 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def __setitem__(self, key, value, *args, **kwargs):
            # Key was inserted before, remove it so we put it at front later
            if key in self:
                del self[key]

            # Too much items on the cache, remove the least recent used
            elif len(self) >= self._maxsize:
                self.popitem(False)

            # Insert the (key, value) pair on the front of the cache
            OrderedDict.__setitem__(self, key, value, *args, **kwargs)
utils.py 文件源码 项目:Sublime-uroboroSQL-formatter 作者: future-architect 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def __setitem__(self, key, value, *args, **kwargs):
            # Reset the cache if we have too much cached entries and start over
            if len(self) >= self._maxsize:
                self.clear()

            # Insert the (key, value) pair on the front of the cache
            dict.__setitem__(self, key, value, *args, **kwargs)
pg.py 文件源码 项目:slack-sql 作者: wang502 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def __setitem__(self, key, value):
            if self._read_only:
                self._read_only_error()
            dict.__setitem__(self, key, value)
pg.py 文件源码 项目:slack-sql 作者: wang502 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def __setitem__(self, key, value):
            if self._read_only:
                self._read_only_error()
            OrderedDict.__setitem__(self, key, value)
pg.py 文件源码 项目:slack-sql 作者: wang502 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def __setitem__(self, key, value):
            if self._read_only:
                self._read_only_error()
            dict.__setitem__(self, key, value)
pg.py 文件源码 项目:slack-sql 作者: wang502 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def __setitem__(self, key, value):
            if self._read_only:
                self._read_only_error()
            OrderedDict.__setitem__(self, key, value)
caches.py 文件源码 项目:pydecor 作者: mplanchard 项目源码 文件源码 阅读 15 收藏 0 点赞 0 评论 0
def __getitem__(self, key, **kwargs):
        value = OrderedDict.__getitem__(self, key)
        del self[key]
        OrderedDict.__setitem__(self, key, value, **kwargs)
        return value
caches.py 文件源码 项目:pydecor 作者: mplanchard 项目源码 文件源码 阅读 14 收藏 0 点赞 0 评论 0
def __setitem__(self, key, value, **kwargs):
        if key in self:
            del self[key]
        OrderedDict.__setitem__(self, key, value, **kwargs)
        if self._max_size and len(self) > self._max_size:
            self.popitem(last=False)
caches.py 文件源码 项目:pydecor 作者: mplanchard 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def __setitem__(self, key, value, **kwargs):
        OrderedDict.__setitem__(self, key, value)
        if self._max_size and len(self) > self._max_size:
            self.popitem(last=False)
caches.py 文件源码 项目:pydecor 作者: mplanchard 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def __setitem__(self, key, value):
        now = time()
        dict.__setitem__(self, key, (value, now))
utils.py 文件源码 项目:uroboroSQL-formatter 作者: future-architect 项目源码 文件源码 阅读 15 收藏 0 点赞 0 评论 0
def __getitem__(self, key, *args, **kwargs):
            # Get the key and remove it from the cache, or raise KeyError
            value = OrderedDict.__getitem__(self, key)
            del self[key]

            # Insert the (key, value) pair on the front of the cache
            OrderedDict.__setitem__(self, key, value)

            # Return the value from the cache
            return value
utils.py 文件源码 项目:uroboroSQL-formatter 作者: future-architect 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def __setitem__(self, key, value, *args, **kwargs):
            # Key was inserted before, remove it so we put it at front later
            if key in self:
                del self[key]

            # Too much items on the cache, remove the least recent used
            elif len(self) >= self._maxsize:
                self.popitem(False)

            # Insert the (key, value) pair on the front of the cache
            OrderedDict.__setitem__(self, key, value, *args, **kwargs)
utils.py 文件源码 项目:uroboroSQL-formatter 作者: future-architect 项目源码 文件源码 阅读 15 收藏 0 点赞 0 评论 0
def __setitem__(self, key, value, *args, **kwargs):
            # Reset the cache if we have too much cached entries and start over
            if len(self) >= self._maxsize:
                self.clear()

            # Insert the (key, value) pair on the front of the cache
            dict.__setitem__(self, key, value, *args, **kwargs)
__init__.py 文件源码 项目:midict 作者: ShenggaoZhu 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def __setattr__(self, item, value):
        """Maps attributes to values.
        Only if initialized and there *isn't* an attribute with this name
        """
        # Note: this allows normal attributes access in the __init__ method

        super_setattr = super(AttrDict, self).__setattr__

        if '_AttrDict__attr2item' not in self.__dict__:  # slot??
            return super_setattr(item, value)

        if item in dir(self):  # any normal attributes are handled normally
            return super_setattr(item, value)

        return self.__setitem__(item, value)
__init__.py 文件源码 项目:midict 作者: ShenggaoZhu 项目源码 文件源码 阅读 39 收藏 0 点赞 0 评论 0
def mset_list(item, index, value):
    'set mulitple items via index of int, slice or list'
    if isinstance(index, (int, slice)):
        item[index] = value
    else:
        map(item.__setitem__, index, value)
__init__.py 文件源码 项目:midict 作者: ShenggaoZhu 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def __setitem__(self, args, value):
        '''
        set values via multi-indexing
        '''
        raise NotImplementedError
__init__.py 文件源码 项目:midict 作者: ShenggaoZhu 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def __setitem__(self, args, value):
        '''
        set values via multi-indexing

        If ``d.indices`` is empty (i.e., no index names and no items are set), index names
        can be created when setting a new item with specified names (``index1`` and ``index2``
        can not be int or slice)::

            d = MIDict()
            d['uid':1, 'name'] = 'jack'
            # d -> MIDict([[1, 'jack']], ['uid', 'name'])

            d = MIDict()
            d[1] = 'jack' # using default index names
            <==> d[:'jack'] = 1
            # d -> MIDict([(1, 'jack')], ['index_1', 'index_2'])

        If ``d.indices`` is not empty, when setting a new item, all indices of the item
        must be specified via ``index1`` and ``index2`` (implicitly or explicitly)::

            d = MIDict([['jack', 1, '192.1']], ['name', 'uid', 'ip'])
            d['tony'] = [2, '192.2']
            <==> d['name':'tony',['uid', 'ip']] = [2, '192.2']
            # the following will not work:
            d['alice', ['uid']] = [3] # raise ValueError

        More examles::

            d = MIDict(jack=1, tony=2)

            d['jack'] = 10 # replace value of key 'jack'
            d['tom'] = 3 # add new key/value
            d['jack'] = 2 # raise ValueExistsError
            d['alice'] = 2 # raise ValueExistsError
            d[:2] = 'jack' # raise ValueExistsError
            d['jack', :] = ['tony', 22] # raise ValueExistsError
            d['jack', :] = ['jack2', 11] # replace item of key 'jack'

        '''
        return _MI_setitem(self, args, value)
trex_stl_types.py 文件源码 项目:trex-http-proxy 作者: alwye 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __setitem__(self, *args, **kwargs):
        OrderedDict.__setitem__(self, *args, **kwargs)
        if len(self) > self.maxlen:
            self.popitem(last = False)


问题


面经


文章

微信
公众号

扫码关注公众号