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)
评论列表
文章目录