1
我循環列表和循環裏面我環路一些文件這是從MongoDB中取出。但在輸出控制檯中,我只能看到一次迭代。 但外環工作正常。當我調試它進入外部循環內部但不進入內部循環。請幫助我。的Python for each循環不工作
client = MongoClient('mongodb://localhost:27017/')
db = client['mydb']
documents = icps_db.user.find({})
name_set = ['john', 'marshal', 'ann' ...]
for name in name_set:
print(name)
for idx, document in enumerate(documents):
print (documents)
if name in document["filtered_words"]:
print ("Found " + name)
else:
print (name + " not found in document ")
輸出 在第二次迭代中未達到行:打印(STR(IDX))。
john
<pymongo.cursor.Cursor object at 0x7faed0ad0910>
Found john
<pymongo.cursor.Cursor object at 0x7faed0ad0910>
john not found in document
<pymongo.cursor.Cursor object at 0x7faed0ad0910>
Found john
<pymongo.cursor.Cursor object at 0x7faed0ad0910>
john not found in document
<pymongo.cursor.Cursor object at 0x7faed0ad0910>
john not found in document
<pymongo.cursor.Cursor object at 0x7faed0ad0910>
Found john
<pymongo.cursor.Cursor object at 0x7faed0ad0910>
john not found in document
<pymongo.cursor.Cursor object at 0x7faed0ad0910>
Found john
<pymongo.cursor.Cursor object at 0x7faed0ad0910>
Found john
<pymongo.cursor.Cursor object at 0x7faed0ad0910>
john not found in document
john
marshal
marshal
你確定'documents'是不是空的?也許首先打印這個集合。 –
'文件'可能是空的。 – kazemakase
文件肯定是空的 – Bodao