Closed flound1129 closed 9 years ago
If we returned None
for an undefined field, there would be no way to tell whether or not a field existed, but contained the value None
.
Couldn't you throw an exception if the field didn't exist, and return None if the field existed and had no value?
For comparison, the (official) JS Api query.get("field") returns undefined whether the field exists or not.
Bear in mind that Javascript and Python are very different in how they define types and falseness. What you are trying to do can work in Javascript because undefined
is falsy, just like null
. In Python, None
is falsy, a non existent attribute is an exception.
But fear not: you can always use python's getattr
. value = getattr(item, 'field', None)
will do exactly what you want.
When I code with ParsePy, my code is invariably strewn with these:
Shouldn't the library just return None if the field is undefined, rather than throwing an exception?