本文整理汇总了Python中UserDict.DictMixin.setdefault方法的典型用法代码示例。如果您正苦于以下问题:Python DictMixin.setdefault方法的具体用法?Python DictMixin.setdefault怎么用?Python DictMixin.setdefault使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserDict.DictMixin
的用法示例。
在下文中一共展示了DictMixin.setdefault方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: copy
# 需要导入模块: from UserDict import DictMixin [as 别名]
# 或者: from UserDict.DictMixin import setdefault [as 别名]
def copy(self):
"""
Return a C{dict} mapping each header name to the last corresponding
header value.
"""
return dict(self.items())
# Python 2.3 DictMixin.setdefault is defined so as not to have a default
# for the value parameter. This is necessary to make this setdefault look
# like dict.setdefault on Python 2.3. -exarkun
示例2: setdefault
# 需要导入模块: from UserDict import DictMixin [as 别名]
# 或者: from UserDict.DictMixin import setdefault [as 别名]
def setdefault(self, name, value=None):
"""
Retrieve the last value for the given header name. If there are no
values present for that header, set the value to C{value} and return
that instead. Note that C{None} is the default for C{value} for
backwards compatibility, but header values may only be of type C{str}.
"""
return DictMixin.setdefault(self, name, value)
# The remaining methods are only for efficiency. The same behavior
# should remain even if they are removed. For details, see
# <http://docs.python.org/lib/module-UserDict.html>.
# -exarkun