问题
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