开发者

App engine - check to see if a property exists within Expando class

开发者 https://www.devze.com 2023-03-13 05:55 出处:网络
What is a good way to check to see if a property is populated in an ex开发者_开发知识库pando class (Python for App Engine)

What is a good way to check to see if a property is populated in an ex开发者_开发知识库pando class (Python for App Engine)

Can I do:

if Expando_class_name.property_name_to_check:
    do = someStuff

Or is that going to give me an error?

Thanks!


Use hasattr:

if hasattr(expando_instance, 'foo'):
  # Do something with expando_instance.foo


A better way is to use the dynamic_properties method.

if 'foo' in entity.dynamic_properties():  pass
0

精彩评论

暂无评论...
验证码 换一张
取 消