本文整理匯總了Python中collections.OrderedDict.__setattr__方法的典型用法代碼示例。如果您正苦於以下問題:Python OrderedDict.__setattr__方法的具體用法?Python OrderedDict.__setattr__怎麽用?Python OrderedDict.__setattr__使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類collections.OrderedDict
的用法示例。
在下文中一共展示了OrderedDict.__setattr__方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __setattr__
# 需要導入模塊: from collections import OrderedDict [as 別名]
# 或者: from collections.OrderedDict import __setattr__ [as 別名]
def __setattr__(self, name, value):
"""
Implemented so that accesses to ``sequence`` raise a warning and are
diverted to the new ``setkeys`` method.
"""
if name == 'sequence':
warnings.warn('Use of the sequence attribute is deprecated.'
' Use the keys method instead.', DeprecationWarning)
# NOTE: doesn't return anything
self.setkeys(value)
else:
# FIXME: do we want to allow arbitrary setting of attributes?
# Or do we want to manage it?
object.__setattr__(self, name, value)
示例2: __setattr__
# 需要導入模塊: from collections import OrderedDict [as 別名]
# 或者: from collections.OrderedDict import __setattr__ [as 別名]
def __setattr__(self, key, val):
if key in Dict.__reserved_names__:
# Either let OrderedDict do its work, or disallow
if key not in Dict.__pure_names__: # pragma: no cover
return _dict.__setattr__(self, key, val)
else:
raise AttributeError('Reserved name, this key can only ' +
'be set via ``d[%r] = X``' % key)
else:
# if isinstance(val, dict): val = Dict(val) -> no, makes a copy!
self[key] = val
示例3: __setattr__
# 需要導入模塊: from collections import OrderedDict [as 別名]
# 或者: from collections.OrderedDict import __setattr__ [as 別名]
def __setattr__(self, key, val):
if key in Dict.__reserved_names__:
# Either let OrderedDict do its work, or disallow
if key not in Dict.__pure_names__:
return _dict.__setattr__(self, key, val)
else:
raise AttributeError('Reserved name, this key can only ' +
'be set via ``d[%r] = X``' % key)
else:
# if isinstance(val, dict): val = Dict(val) -> no, makes a copy!
self[key] = val