本文整理汇总了Python中collections.ChainMap.__delitem__方法的典型用法代码示例。如果您正苦于以下问题:Python ChainMap.__delitem__方法的具体用法?Python ChainMap.__delitem__怎么用?Python ChainMap.__delitem__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类collections.ChainMap
的用法示例。
在下文中一共展示了ChainMap.__delitem__方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: it
# 需要导入模块: from collections import ChainMap [as 别名]
# 或者: from collections.ChainMap import __delitem__ [as 别名]
#.........这里部分代码省略.........
def rec_new(self, val):
"""Recursively add a new value and its children to me.
Args:
val (LispVal): The value to be added.
Returns:
LispVal: The added value.
"""
if val not in self.things:
for child in val.children():
self.rec_new(child)
self.new(val)
return val
def add_rec_new(self, k, val):
"""Recursively add a new value and its children to me, and assign a
variable to it.
Args:
k (str): The name of the variable to assign.
val (LispVal): The value to be added and assigned.
Returns:
LispVal: The added value.
"""
self.rec_new(val)
self[k] = val
return val
def new_child(self):
"""Get a new child :class:`Environment`.
The child's scopes will be mine, with an additional empty innermost
one.
Returns:
Environment: The child.
"""
child = Environment(self.globals, self.max_things)
child.scopes = self.scopes.new_child()
child.things = WeakSet(self.things)
return child
def __getitem__(self, k):
"""Look up a variable.
Args:
k (str): The name of the variable to look up.
Returns:
LispVal: The value assigned to the variable.
Raises:
KeyError: If the variable has not been assigned to.
"""
chain = ChainMap(self.scopes, self.globals)
return chain.__getitem__(k)
def __setitem__(self, k, val):
"""Assign to a variable.
This will only mutate my innermost scope.
This does **not** :meth:`add <new>` anything to me.
Args:
k (str): The name of the variable to assign to.
val (LispVal): The value to assign to the variable.
"""
self.scopes.__setitem__(k, val)
def __delitem__(self, k):
"""Clear a variable.
This will only mutate the innermost scope.
Args:
k (str): The name of the variable to clear.
Raises:
KeyError: If the variable has not been assigned to.
"""
return self.scopes.__delitem__(k)
def __contains__(self, k):
"""Check whether a variable has been assigned to.
This is **not** the same kind of element-of as described in the
class documentation.
Args:
k (str): The name of the variable to check.
Returns:
bool: Whether or not the variable has been assigned to.
"""
chain = ChainMap(self.scopes, self.globals)
return chain.__contains__(k)