本文整理匯總了Python中diffpy.srfit.util.ordereddict.OrderedDict.itervalues方法的典型用法代碼示例。如果您正苦於以下問題:Python OrderedDict.itervalues方法的具體用法?Python OrderedDict.itervalues怎麽用?Python OrderedDict.itervalues使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類diffpy.srfit.util.ordereddict.OrderedDict
的用法示例。
在下文中一共展示了OrderedDict.itervalues方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: RecipeContainer
# 需要導入模塊: from diffpy.srfit.util.ordereddict import OrderedDict [as 別名]
# 或者: from diffpy.srfit.util.ordereddict.OrderedDict import itervalues [as 別名]
class RecipeContainer(Observable, Configurable, Validatable):
"""Base class for organizing pieces of a FitRecipe.
RecipeContainers are hierarchical organizations of Parameters and other
RecipeContainers. This class provides attribute-access to these contained
objects. Parameters and other RecipeContainers can be found within the
hierarchy with the _locateManagedObject method.
A RecipeContainer can manage dictionaries for that store various objects.
These dictionaries can be added to the RecipeContainer using the _manage
method. RecipeContainer methods that add, remove or retrieve objects will
work with any managed dictionary. This makes it easy to add new types of
objects to be contained by a RecipeContainer. By default, the
RecipeContainer is configured to manage an OrderedDict of Parameter
objects.
RecipeContainer is an Observable, and observes its managed objects and
Parameters. This allows hierarchical calculation elements, such as
ProfileGenerator, to detect changes in Parameters and Restraints on which
it may depend.
Attributes
name -- A name for this RecipeContainer. Names should be unique
within a RecipeContainer and should be valid attribute
names.
_parameters -- A managed OrderedDict of contained Parameters.
__managed -- A list of managed dictionaries. This is used for
attribute access, addition and removal.
_configobjs -- A set of configurable objects that must know of
configuration changes within this object.
Properties
names -- Variable names (read only). See getNames.
values -- Variable values (read only). See getValues.
"""
names = property(lambda self: self.getNames())
values = property(lambda self: self.getValues())
def __init__(self, name):
Observable.__init__(self)
Configurable.__init__(self)
validateName(name)
self.name = name
self._parameters = OrderedDict()
self.__managed = []
self._manage(self._parameters)
return
def _manage(self, d):
"""Manage a dictionary of objects.
This adds the dictionary to the __managed list. Dictionaries in
__managed are used for attribute access, addition, and removal.
"""
self.__managed.append(d)
return
def _iterManaged(self):
"""Get iterator over managed objects."""
return chain(*(d.values() for d in self.__managed))
def iterPars(self, name=".", recurse=True):
"""Iterate over Parameters.
name -- Select parameters with this name (regular expression,
default ".").
recurse -- Recurse into managed objects (default True)
"""
for par in self._parameters.itervalues():
if re.match(name, par.name):
yield par
if not recurse:
return
# Iterate over objects within the managed dictionaries.
managed = self.__managed[:]
managed.remove(self._parameters)
for m in managed:
for obj in m.values():
if hasattr(obj, "iterPars"):
for par in obj.iterPars(name=name):
yield par
return
def __iter__(self):
"""Iterate over top-level parameters."""
return self._parameters.itervalues()
def __len__(self):
"""Get number of top-level parameters."""
return len(self._parameters)
def __getitem__(self, idx):
"""Get top-level parameters by index."""
return self._parameters.values()[idx]
#.........這裏部分代碼省略.........