Python 方法调用后评估的方法参数
Python method parameter evaluated after method invocation
在 App Engine NDB documentation 中,有以下内容:
FlexEmployee.query(FlexEmployee.location == 'SF')
为什么不首先计算 "FlexEmployee.location == 'SF'" 并将布尔结果传递给 query()?
诀窍是基础 ndb.Property
class 覆盖 __eq__
方法,因此它不是 return 布尔值而是传递的 FilterNode class进入实际查询。
因此,它 是 在调用 query
之前求值的,但该求值的结果不是布尔值。
由 FlexEmployee.location
编辑的对象 return 定义了一个 __eq__
方法,它不是 return 布尔值 - 它 return 是一个过滤器对象,表示表达式 "employee.location == 'SF'"。查询方法使用在构建在底层存储上运行的查询时传入的过滤器对象。
property class also defines the magic methods 使您能够在这些表达式中使用 >、<、>=、<= 和 !=。
在 App Engine NDB documentation 中,有以下内容:
FlexEmployee.query(FlexEmployee.location == 'SF')
为什么不首先计算 "FlexEmployee.location == 'SF'" 并将布尔结果传递给 query()?
诀窍是基础 ndb.Property
class 覆盖 __eq__
方法,因此它不是 return 布尔值而是传递的 FilterNode class进入实际查询。
因此,它 是 在调用 query
之前求值的,但该求值的结果不是布尔值。
由 FlexEmployee.location
编辑的对象 return 定义了一个 __eq__
方法,它不是 return 布尔值 - 它 return 是一个过滤器对象,表示表达式 "employee.location == 'SF'"。查询方法使用在构建在底层存储上运行的查询时传入的过滤器对象。
property class also defines the magic methods 使您能够在这些表达式中使用 >、<、>=、<= 和 !=。