句子结束双倍空间:t 填充栏:70 结束: ... ''spam'':{''ham'':2, ''badger'':3}})Bunch(eggs=1, spam=Bunch(ham=2, badger=3)) Keyword Arguments:mapping -- a mapping objectgetitems -- a function that takes the mapping as a parameterand returns an iterable of (key, value) pairs. If notprovided, the items method on the mapping object will beused, or (key, mapping[key]) values will be generated ifthe mapping object does not provide an items method. Note that getitems will be applied recursively to each valuein the mapping. It should raise a TypeError if it isapplied to an object for which it cannot produce(key, value) pairs."""# determine which items() method to useif getitems is None:try:getitems = type(mapping).itemsexcept AttributeError:getitems = _items# build the Bunch from the mapping, recursivelyresult = cls()for key, value in getitems(mapping):try:value = cls.frommapping(value, getitems=getitems)except TypeError:passsetattr(result, key, value)return resultdef _items(mapping):"""Produces (key, value) pairs from a mapping object. Intended for use with mapping objects that do not supply anitems method."""for key in mapping:yield key, mapping[key]Open Issues===========What should the type be named? Some suggestions include ''Bunch'',''Record'' and ''Struct''. Where should the type be placed? The current suggestion is thecollections module.References========== ...Local Variables:mode: indented-textindent-tabs-mode: nilsentence-end-double-space: tfill-column: 70End:推荐答案 修订版:1.0 最后修改:Last-Modified: 日期:2004/11 / 29 16:00:00 Date: 2004/11/29 16:00:00 这篇关于pre-PEP通用对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-22 17:36