4

什么是检查属性是否填充在扩展类中的好方法(Python for App Engine)

我可不可以做:

if Expando_class_name.property_name_to_check:
    do = someStuff

或者这会给我一个错误?

谢谢!

4

2 回答 2

5

使用hasattr

if hasattr(expando_instance, 'foo'):
  # Do something with expando_instance.foo
于 2011-06-14T05:10:44.993 回答
2

更好的方法是使用 dynamic_properties 方法。

if 'foo' in entity.dynamic_properties():  pass
于 2012-10-25T20:16:42.763 回答