Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在python中,字符串索引必须是代码中一个位置的整数_Python - Fatal编程技术网

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

在python中,字符串索引必须是代码中一个位置的整数,python,Python,我在ig=image['images']行中得到错误。我尝试将其更改为ig=int(image['images']),但我得到了相同的错误。游标是否返回dict对象的列表?尝试print image和print type(image)。对于print image,我得到“ok”,对于print type(image),我在pymongo中得到@ZdaR yes,它返回一个带有Unicode键和值的字典,那么为什么我会得到这个错误……?:(@Svati是否打印id1 import pymongo

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

游标是否返回
dict
对象的列表?尝试
print image
print type(image)
。对于print image,我得到“ok”,对于print type(image),我在pymongo中得到@ZdaR yes,它返回一个带有Unicode键和值的字典,那么为什么我会得到这个错误……?:(@Svati是否打印id1
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
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