Is there a way (using evalor something else) to evaluate intolerably boolean expressions in python?
eval
We will see:
>>> x = 3 >>> 5 < x < y False
Hop! This is very nice because it will be false, regardless of value y. The fact is that it ycan even be undefined, and I would like to get this exception. How can I get python to evaluate all expressions even if it knows the result in advance?
y
I hope I get it! ThanksManuel
Edit: Please keep in mind that the expression should not be changed, just an evaluation method.
all([5 < x, x < y])
(5 < x) & (x < y)
- &, ( and, or, chaining, all/any). ( ), , ; -).
&
and
or
all
any
, , .
a = foo() b = bar() if a and b: ...
, all([5 < x, x < y]), , , (&) - , , , , , ???. , , .
NameError, b (.. ), a - false, , , bugfinder, .
NameError
b
a
>>> x = 3 >>> y > x > 5 Traceback (most recent call last): File "", line 1, in NameError: name 'y' is not defined
, , , . , x or y() x() or y() . , , pylint, pyflakes pychecker.
x or y()
x() or y()
If you receive instructions from the user and want to execute it using your own semantics, you must analyze it yourself with a tool such as pyparsing. It is dirty and insecure to evaluate the code of another in the middle of yours, mixing their results with yours, and this is confused to evaluate what looks like Python code, but with different semantics.
pyparsing
Source: https://habr.com/ru/post/1732965/More articles:Access denied message when deploying spring application to tomcat 6 - javaHow to delete a file from an Android application - androidHow to run WebDevServer from a .sln file without opening Visual Studio 2008 - visual-studio-2008adb cannot find my Android debugging device. What for? - javaEquivalent to toString () in Eclipse for debugging GDB - c ++UploadError 403 in swfupload for Firefox - javateam denial Set unused - databaseКак форматировать диск в формате FAT 16 с помощью VB.NET без взаимодействия с пользователем - formatHow to change the language of a specific page on a Django website - djangoFlex Preloader sometimes doesn't show until it reaches 100% - flexAll Articles