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


Python OrderedDict.__setitem__方法代碼示例

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


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

示例1: update

# 需要導入模塊: from collections import OrderedDict [as 別名]
# 或者: from collections.OrderedDict import __setitem__ [as 別名]
def update(self, others):
        """ Same as a regular `dict.update`, however, since pypy's `dict.update`
        doesn't go through `dict.__setitem__`, this is used to ensure it does

        Args:
            others (iterable): a dictionary or iterable containing key/value pairs
        """

        if type(others) == dict:
            for k,v in others.items():
                self.__setitem__(k,v)
        elif type(others) in [list, tuple]:
            for k,v in others:
                self.__setitem__(k,v)
        else:
            raise ValueError('Iteratable/dict must be in key, value pairs') 
開發者ID:betteridiot,項目名稱:bamnostic,代碼行數:18,代碼來源:utils.py

示例2: __setitem__

# 需要導入模塊: from collections import OrderedDict [as 別名]
# 或者: from collections.OrderedDict import __setitem__ [as 別名]
def __setitem__(self, key, value):
        """Basic setter that adds new item to dictionary, and then performs cull()
        to ensure max_cache has not been violated.

        Args:
            key (str): immutable dictionary key
            value (any): any dictionary value
        """

        OrderedDict.__setitem__(self, key, value)
        self.cull()

# The BAM format uses byte encoding to compress alignment data. One such
# compression is how operations are stored: they are stored and an
# array of integers. These integers are mapped to their respective
# operation identifier. Below is the mapping utility. 
開發者ID:betteridiot,項目名稱:bamnostic,代碼行數:18,代碼來源:utils.py

示例3: __setitem__

# 需要導入模塊: from collections import OrderedDict [as 別名]
# 或者: from collections.OrderedDict import __setitem__ [as 別名]
def __setitem__(self, key, val):
        if key == '_{}__locked'.format(type(self).__name__):
            OrderedDict.__setitem__(self, key, val)
        elif hasattr(self, '_{}__locked'.format(type(self).__name__)):
            if self.__locked:
                raise PermissionError('Options\' dictionnary is locked and cannot be changed.')
            if type(val) == dict:
                val = OptionsDict(val)
                OrderedDict.__setitem__(self, key, val)
            elif isinstance(key, str) and '.' in key:
                first_key, other_keys = key.split('.', maxsplit=1)
                if first_key not in self:
                    self[first_key] = OptionsDict({})
                self[first_key][other_keys] = val
            else:
                OrderedDict.__setitem__(self, key, val)
        else:
            raise PermissionError('Tried to access Options\' dictionnary bypassing the lock feature.') 
開發者ID:Cadene,項目名稱:bootstrap.pytorch,代碼行數:20,代碼來源:options.py

示例4: __setitem__

# 需要導入模塊: from collections import OrderedDict [as 別名]
# 或者: from collections.OrderedDict import __setitem__ [as 別名]
def __setitem__(self, item, value):
        self.reverse[value] = item
        dict.__setitem__(self, item, value) 
開發者ID:SrikanthVelpuri,項目名稱:tf-pose,代碼行數:5,代碼來源:pgcollections.py

示例5: __setitem__

# 需要導入模塊: from collections import OrderedDict [as 別名]
# 或者: from collections.OrderedDict import __setitem__ [as 別名]
def __setitem__(self, *args, **kwargs):
        if self.readonly:
            raise KeyError("object in read-only mode")
        else:
            return OrderedDict.__setitem__(self, *args, **kwargs) 
開發者ID:fabiencro,項目名稱:knmt,代碼行數:7,代碼來源:argument_parsing_tools.py

示例6: insert_section

# 需要導入模塊: from collections import OrderedDict [as 別名]
# 或者: from collections.OrderedDict import __setitem__ [as 別名]
def insert_section(self, name, content, even_if_readonly=False, keep_at_bottom=None, overwrite=False):
        if self.readonly and not even_if_readonly:
            raise ValueError()
        if name in self and not overwrite:
            raise ValueError()
        super(OrderedNamespace, self).__setitem__(name, content)
        if keep_at_bottom is not None:
            metadata = self[keep_at_bottom]
            del self[keep_at_bottom]
            super(OrderedNamespace, self).__setitem__(keep_at_bottom, metadata) 
開發者ID:fabiencro,項目名稱:knmt,代碼行數:12,代碼來源:argument_parsing_tools.py

示例7: __setitem__

# 需要導入模塊: from collections import OrderedDict [as 別名]
# 或者: from collections.OrderedDict import __setitem__ [as 別名]
def __setitem__(self, key, value):

        OrderedDict.__setitem__(self, key, value)
        self._check_size_limit() 
開發者ID:lekhakpadmanabh,項目名稱:Summarizer,代碼行數:6,代碼來源:utilities.py

示例8: __setitem__

# 需要導入模塊: from collections import OrderedDict [as 別名]
# 或者: from collections.OrderedDict import __setitem__ [as 別名]
def __setitem__(self, key, value):
        contains_key = key in self
        if len(self) - int(contains_key) >= self._capacity:
            self.popitem(last=False)  # pop the first element if full
        OrderedDict.__setitem__(self, key, value) 
開發者ID:JQ-Networks,項目名稱:UnifiedMessageRelay,代碼行數:7,代碼來源:UMRMessageRelation.py

示例9: __setitem__

# 需要導入模塊: from collections import OrderedDict [as 別名]
# 或者: from collections.OrderedDict import __setitem__ [as 別名]
def __setitem__(self, key, val):
        if isinstance(val, OrderedDict):
            self._unique += 1
            key = "{}. [{}]".format(str(self._unique), key)
        OrderedDict.__setitem__(self, key, val) 
開發者ID:deeptools,項目名稱:pyGenomeTracks,代碼行數:7,代碼來源:tracksClass.py

示例10: __setitem__

# 需要導入模塊: from collections import OrderedDict [as 別名]
# 或者: from collections.OrderedDict import __setitem__ [as 別名]
def __setitem__(self, key: CacheKey, value: CacheValue) -> None:
        """Store a new views, potentially discarding an old value."""
        if key not in self:
            if len(self) >= self.cache_size:
                self.popitem(last=False)
        OrderedDict.__setitem__(self, key, value) 
開發者ID:willmcgugan,項目名稱:rich,代碼行數:8,代碼來源:_lru_cache.py

示例11: __getitem__

# 需要導入模塊: from collections import OrderedDict [as 別名]
# 或者: from collections.OrderedDict import __setitem__ [as 別名]
def __getitem__(self: Dict[CacheKey, CacheValue], key: CacheKey) -> CacheValue:
        """Gets the item, but also makes it most recent."""
        value: CacheValue = OrderedDict.__getitem__(self, key)
        OrderedDict.__delitem__(self, key)
        OrderedDict.__setitem__(self, key, value)
        return value 
開發者ID:willmcgugan,項目名稱:rich,代碼行數:8,代碼來源:_lru_cache.py

示例12: _set_key

# 需要導入模塊: from collections import OrderedDict [as 別名]
# 或者: from collections.OrderedDict import __setitem__ [as 別名]
def _set_key(self, key, value, docstr=''):
        if key in self:
            raise ValueError('Cannot overwrite a key.')
        dict.__setitem__(self, key, value)
        self._doc[key] = docstr 
開發者ID:OGGM,項目名稱:oggm,代碼行數:7,代碼來源:cfg.py

示例13: __setitem__

# 需要導入模塊: from collections import OrderedDict [as 別名]
# 或者: from collections.OrderedDict import __setitem__ [as 別名]
def __setitem__(self, key, value):
        # Overrides the original dic to separate value and documentation
        global CONFIG_MODIFIED
        try:
            self._set_key(key, value[0], docstr=value[1])
            CONFIG_MODIFIED = True
        except BaseException:
            raise ValueError('DocumentedDict accepts only tuple of len 2') 
開發者ID:OGGM,項目名稱:oggm,代碼行數:10,代碼來源:cfg.py

示例14: __setitem__

# 需要導入模塊: from collections import OrderedDict [as 別名]
# 或者: from collections.OrderedDict import __setitem__ [as 別名]
def __setitem__(self, key, value):
        OrderedDict.__setitem__(self, key, value)
        self._check_size_limit() 
開發者ID:cloudify-cosmo,項目名稱:cloudify-manager,代碼行數:5,代碼來源:postgres_publisher.py

示例15: __setitem__

# 需要導入模塊: from collections import OrderedDict [as 別名]
# 或者: from collections.OrderedDict import __setitem__ [as 別名]
def __setitem__(self, key, value):
        if key in self:
            del self[key]
        OrderedDict.__setitem__(self, key, value)
        self._check_limit() 
開發者ID:tehkillerbee,項目名稱:mopidy-tidal,代碼行數:7,代碼來源:lru_cache.py


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