Pass!,! =, ~, <,> As parameters

I want to be able to pass arguments like this:

 fn(a>=b) or fn(a!=b) 

I have seen this behavior in DjangoORM and SQLAlchemy, but I do not know how to achieve it.

+7
source share
1 answer

ORMs use special methods for classes for a and b to bind to statements and configure what is done.

>= for is handled by the object.__ge__() method, and != calls object.__ne__() .

Typically, the ORM object used for a returns a new object with the applicable operation, which allows you to perform chain operations, and the fn() function expects such an ORM object and will read the operation status there.

+8
source

All Articles