本文整理匯總了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')
示例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.
示例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.')
示例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)
示例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)
示例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)
示例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()
示例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)
示例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)
示例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)
示例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
示例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
示例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')
示例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()
示例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()