In general, a math expression will be entered at the input, in which Y will be calculated and there is X (with the help of a cycle it will go over the list of X's and substitute). After using the lists x-s and y-s will be built graph. How safer to do all this? Tell me
- oneDo you have a dangerous solution? Show your code. - VladD
- No, there is no code yet. Everything is on the level of theory. It would be possible to use eval, but it is necessary to make restrictions, and this is not cool, because you can't shut out everything at once. Regarding a very, very safe way, I exaggerated, but can you tell at least some suitable solution? Can already have some kind of annual salary? I saw on js there is math.eval, Duc may have something similar for a python - Daniel Grishaev
- Here, a friend writes about his bike: "evalidate: safe processing of user expressions" - insolor
- I would say you need an arithmetic expressions parser. This is not an easy thing, and the ball will not work. There are ready-made parsers, but their syntax is fixed in advance (and how else?), And you have no easy way to fix it. // But once in a lifetime, you need to write your parser anyway. - VladD
- Yes, thank you, I will try) - Daniil Grishaev
|
1 answer
I recommend to take a look at symPy
A simple example of an expression:
from sympy.parsing.sympy_parser import parse_expr func = parse_expr( "x + y" ) print( func ) # x + y print( func.args ) # x, y x, y = func.args print( func.n( subs={x:1, y:2} ) ) # 3.0000000 |