当前位置: 首页>>代码示例>>Python>>正文


Python OrderedDict.get方法代码示例

本文整理汇总了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):
#.........这里部分代码省略.........
开发者ID:XiaohaoYang,项目名称:diffpy.srfit,代码行数:103,代码来源:equationmod.py


注:本文中的diffpy.srfit.util.ordereddict.OrderedDict.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。