I have list like:
['name','country_id', 'price','rate','discount', 'qty']
and a string expression like
exp = 'qty * price - discount + 100'
I want to convert this expression into
exp = 'obj.qty * obj.price - obj.discount + 100'
as I wanna eval this expression like eval(exp or False, dict(obj=my_obj))
my question is what would be the best way to generate the expression for python eval evaluation….
Of course you have to be very careful using eval. Would be interesting to know why you need to use eval for this at all
This way makes it harder for something bad to happen if a malicious user finds a way to put non numeric data in the fields