gpt4 book ai didi

python - 字符串索引在 python 中的一个代码位置必须是整数

转载 作者:太空宇宙 更新时间:2023-11-04 05:48:12 24 4
gpt4 key购买 nike

import pymongo
import sys

client=pymongo.MongoClient('localhost',27017)
db=client.rop

try:
cntcur=db.albums.aggregate([{"$unwind":"$images"},"$group":"_id":"null","count":{'$sum':1}}}])
cursor1=db.images.find()

for im in cursor1:
id1=int(im['_id'])
cnt=0
cursor= db.albums.aggregate([{"$unwind":"$images"}])
print id1
for image in cursor:
print "moving to images collection"
ig=image['images']
if (id1 == ig):
break;
else:
cnt=cnt+1
if (cnt == cntr):
print "removing"
db.images.remove({'_id':id1})



except Exception as e:
print "unexpected error", type(e),e

我在行 ig=image['images'] 中遇到错误。我尝试将其更改为 ig=int(image['images']),但我遇到了同样的错误。

最佳答案

import pymongo
import sys
client = pymongo.MongoClient('localhost',27017)
db=client.rop
try:
cursor1=db.images.find()
for im in cursor:
id1=int(im['_id'])
print id1
cnt=0
cursor=db.albums.find()
for image in cursor:
ig=image['images']
for data in ig:
if (id1 == data):
cnt=1
break;
if cnt==0:
print "removing"
db.images.remove({'_id':id1})
except Exception as e:
print "unexpected error",type(e) , e

关于python - 字符串索引在 python 中的一个代码位置必须是整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31335762/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com