Python: Avoid short circuit evaluation

前端 未结 3 1431
暖寄归人
暖寄归人 2020-12-10 01:10

This is a problem that occured to me while working on a Django project. It\'s about form validation.

In Django, when you have a submitted form, you can call is

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-10 01:59

    You can use Clever infix hack for defining your own Boolean operators
    aand=Infix(lambda x,y: bool(x) and bool(y))
    1 |aand| 2 will return True instead of 1

提交回复
热议问题