Store named expression's current value in a python variable
Dear All,
I can get the value of a named expression using this command:
solver.setup.named_expressions.compute(names = ["my_expression"])
Information is reported in the console.
Is there a way to store the value in a python variable?
**
For example:
**Input:
expression_value = command_that_I'm_looking_for
print(expression_value)
print(expression_value + 2000)
**Output: **
25
2025
0
Answers
-
Hi Hristo,
just try the following way to get that value stored in the variable
- val = solver.settings.setup.named_expressions["my_expression"].definition()
- print(val)
definition returns the expression
- val = solver.settings.setup.named_expressions["my_expression"].get_value()
- print(val)
get_value() evaluates and return the value
Thanks!
0 -
@abhishekchitwar definition() should return the expression string (e.g., "2 + 2"). Is that what @Hristo wants or does he want the result, 4? That's via get_value:
- expr_val = solver.settings.setup.named_expressions["test_expr_1"].get_value()
1 -
2