Documentation on your simpleeval package (on github) has an explanation on how add ^ operator, but lacks an example of how operators paramater work
is through a dict with lambda, just like functions paramater work?
already tested the following and it was the only way I could make it work
s = SimpleEval()
s.operators[ast.BitOr] = op.or_
the problem with this is that Or can not be added as or
Also custom functions that are not available in ast package are trickier (could not make it work)
for example lets take operator juggler:
1 juggler 7 returns 5, since juggler takes 1 from 7, and since the result is higher that 1, takes another 1 from the result (6) ending in 5
if the example does not make much sense is because I'm forcing it to be a custom operator
This triggers the fact that when any operator is added DEFAULT OPERATORS are ignored:
if anything is added through parameter operator= a conditional on the constructor (__init__) makes it imposible to append new operators to the default operators
Is this a feature? an optimization feature? maybe I am not using the package correctly
I thought the documentation could use something like:
adding operator Or would require the following:
simple_eval("True Or False", operators={"Or": lambda x, y: x | y})
returns True
simple_eval("1 juggler 7", operators={"juggler": lambda x, y:
y - 2 *x if (y - x) > x else y - x })
returns 5
this becomes extremely handy when using complex operators for time series when comparisons are time wise (maybe sent in tuple form)
simple_eval("(t0, t1) crosses_above (s0, s1)",
operators={"crosses_above": lambda t, s: t[1] > s[1] if t[0] < s[0] else False})
returns True or False depending on the case
when: t[0, 1] = 2, 4 and s[0, 1] = 2.5, 3.5; crosses_above returns True
when: t[0, 1] = 2, 3 and s[0, 1] = 2.5, 3.5; crosses_above returns False
When this issue is clear to me I could open a fork and send the PR with the respective changes into the documentation
Also I am impressed at your work, wish you a wonderful day sir
Documentation on your simpleeval package (on github) has an explanation on how add
^operator, but lacks an example of howoperatorsparamater workis through a
dictwithlambda, just likefunctionsparamater work?already tested the following and it was the only way I could make it work
the problem with this is that
Orcan not be added asorAlso custom functions that are not available in
astpackage are trickier (could not make it work)for example lets take operator
juggler:1 juggler 7returns5, sincejugglertakes 1 from 7, and since the result is higher that 1, takes another 1 from the result (6) ending in 5if the example does not make much sense is because I'm forcing it to be a custom operator
This triggers the fact that when any operator is added DEFAULT OPERATORS are ignored:
if anything is added through parameter
operator=a conditional on the constructor (__init__) makes it imposible to append new operators to the default operatorsIs this a feature? an optimization feature? maybe I am not using the package correctly
I thought the documentation could use something like:
this becomes extremely handy when using complex operators for time series when comparisons are time wise (maybe sent in tuple form)
When this issue is clear to me I could open a fork and send the PR with the respective changes into the documentation
Also I am impressed at your work, wish you a wonderful day sir