I have a field like this in a MongoDB table: "answers":[]
How can I do conditional branch if I want to know it is an empty list?
I'm using Python 2.7 and MongoEngine 0.15.0.
This is what I am trying to do: if object_name.answer is None:
Is that correct? Please point out if I am on the right track.
Unless I'm misunderstanding the question, this is a general python question (unless you are asking for how to query through mongoengine).
It all depends:
if object_name.answer:
...
if object_name.answer == []:
...
elif object_name.answer is None:
...
@candycrusher does that answer your question? If yes, then let's close this :)
Not to nitpick, but for future readers, I suspect you meant to quote:
if not object_name.answer:
...
I suspect most folks would have figured that out, but just in case...
@candycrusher does that answer your question? If yes, then let's close this :)
Yes, absolutely did. I appreciate your help. Also, I would like to keep my pace to contribute to open source someday. The web greatwall in China makes me very hard to climb finally to here.
Not to nitpick, but for future readers, I suspect you meant to quote:
if not object_name.answer: ...I suspect most folks would have figured that out, but just in case...
Exactly, that's what I need to note and keep this good habit.
Most helpful comment
Not to nitpick, but for future readers, I suspect you meant to quote:
I suspect most folks would have figured that out, but just in case...