friendlysam.opt.Variable.evaluate¶
-
Variable.
evaluate
(replace=None, evaluators=None)¶ Evaluate a variable.
See
Operation.evaluate()
for a general explanation of expression evaluation.A
Variable
is evaluated with the following priority order:- If it has a
value
, that is returned.
2. Otherwise, if the variable is a key in the replace dictionary, the corresponding value is returned.
- Otherwise, the variable itself is returned.
Parameters: - replace (dict, optional) – Replacements.
- evaluators (dict, optional) – Has no effect. Just included to be
compatible with the signature of
Operation.evaluate()
.
Examples
>>> x = Variable('x') >>> x.evaluate() == x True >>> x.evaluate({x: 5}) == 5 True
>>> x.value = -1 >>> x.evaluate() == -1 True >>> x.evaluate({x: 5}) == -1 # .value goes first! True
>>> del x.value >>> x.value Traceback (most recent call last): ... friendlysam.opt.NoValueError
- If it has a