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

耗尽温柔 提交于 2020-01-03 18:50:18

问题


What is a good way to check to see if a property is populated in an expando 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!


回答1:


Use hasattr:

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



回答2:


A better way is to use the dynamic_properties method.

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


来源:https://stackoverflow.com/questions/6339032/app-engine-check-to-see-if-a-property-exists-within-expando-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!