本文整理匯總了Python中diffpy.srfit.util.ordereddict.OrderedDict.get方法的典型用法代碼示例。如果您正苦於以下問題:Python OrderedDict.get方法的具體用法?Python OrderedDict.get怎麽用?Python OrderedDict.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類diffpy.srfit.util.ordereddict.OrderedDict
的用法示例。
在下文中一共展示了OrderedDict.get方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Equation
# 需要導入模塊: from diffpy.srfit.util.ordereddict import OrderedDict [as 別名]
# 或者: from diffpy.srfit.util.ordereddict.OrderedDict import get [as 別名]
class Equation(Operator):
"""Class for holding and evaluating a Literal tree.
Instances have attributes that are the non-const Arguments of the tree
(accessed by name) and a __call__ method that evaluates the tree. It is
assumed, but not enforced that Arguments have unique names. If this is not
the case, then one should keep its own list of Arguments.
The tree is scanned for errors when it is added. Thus, the tree should be
complete before putting it inside an Equation.
Equations can act as Operator nodes within a literal tree. In this context,
they evaluate as the root node, but provide a calling interface that
accepts new argument values for the literal tree.
Attributes
root -- The root Literal of the equation tree
argdict -- An OrderedDict of Arguments from the root.
args -- Property that gets the values of argdict.
Operator Attributes
args -- List of Literal arguments, set with 'addLiteral'
name -- A name for this operator. e.g. "add" or "sin"
nin -- Number of inputs (<1 means this is variable)
nout -- Number of outputs
operation -- Function that performs the operation. e.g. numpy.add.
symbol -- The symbolic representation. e.g. "+" or "sin".
_value -- The value of the Operator.
value -- Property for 'getValue'.
"""
def __init__(self, name = None, root = None):
"""Initialize.
name -- A name for this Equation.
root -- The root node of the Literal tree (default None). If root
is not passed here, you must call the 'setRoot' method to
set or change the root node.
"""
# Operator stuff. We circumvent Operator.__init__ since we're using
# args as a property. We cannot set it, as the Operator tries to do.
if name is None and root is not None:
name = "eq_%s"%root.name
Literal.__init__(self, name)
self.symbol = name
self.nin = None
self.nout = 1
self.operation = self.__call__
self.root = None
self.argdict = OrderedDict()
if root is not None:
self.setRoot(root)
return
def _getArgs(self):
return self.argdict.values()
args = property(_getArgs)
def __getattr__(self, name):
"""Gives access to the Arguments as attributes."""
arg = self.argdict.get(name)
if arg is None:
raise AttributeError("No argument named '%s' here"%name)
return arg
def setRoot(self, root):
"""Set the root of the Literal tree.
Raises:
ValueError if errors are found in the Literal tree.
"""
# Validate the new root
validate(root)
# Stop observing the old root
if self.root is not None:
self.root.removeObserver(self._flush)
# Add the new root
self.root = root
self.root.addObserver(self._flush)
self._flush(self)
# Get the args
args = getArgs(root, getconsts=False)
self.argdict = OrderedDict( [(arg.name, arg) for arg in args] )
# Set Operator attributes
self.nin = len(self.args)
return
def __call__(self, *args, **kw):
#.........這裏部分代碼省略.........