python - Map comparison operators to function call -
i'm building dsl form validation in python, , 1 of requirements able specify field should greater or less constant or field value. result, i'm trying map operators <, >, <= , >= equivalent functions in operator module, can called during field validation.
i realise create dictionary map operator function, there nicer way it? there way access python's built-in mapping?
as far i'm aware, there no built-in dictionary mapping string ">" function operator.lt, etc.
as others have pointed out, python interpreter not make use of such dictionary, since process of parsing , executing python code first translate character sequence ">" token representing operator, translated bytecode, , result of executing bytecode execute __lt__ method directly, rather via operator.lt function.
Comments
Post a Comment