python - Typeerror:list indices must be integers, not tuple -
i have got error in type of indices. tried run code got complied error can see in python idle below.
the code:
def triples(self, (sub, pred, obj)): #generator on triple store. #returns triples match given triple pattern. # check terms present in order use correct index: try: if sub != none: if pred != none: # sub pred obj if obj != none: if obj in self._spo[sub][pred]: yield (sub, pred, obj) # sub pred none else: retobj in self._spo[sub][pred]: yield (sub, pred, retobj) else: # sub none obj if obj != none: retpred in self._osp[obj][sub]: yield (sub, retpred, obj) # sub none none else: retpred, objset in self._spo[sub].items(): retobj in objset: yield (sub, retpred, retobj) else: if pred != none: # none pred obj if obj != none: retsub in self._pos[pred][obj]: yield (retsub, pred, obj) # none pred none else: retobj, subset in self._pos[pred].items(): retsub in subset: yield (retsub, pred, retobj) else: # none none obj if obj != none: retsub, predset in self._osp[obj].items(): retpred in predset: yield (retsub, retpred, obj) # none none none else: retsub, predset in self._spo.items(): retpred, objset in predset.items(): retobj in objset: yield (retsub, retpred, retobj) # keyerrors occur if query term wasn't in index, yield nothing: except keyerror: pass
the following error after executing in python idle. error got thought indices in python idle.
list(movie_graph.triples(("blade_runner","directed_by",none))) [("blade_runner","directed_by","ridle_scott")]
traceback (most recent call last) file "", line 1, in list(movie_graph.triples(("blade_runner","directed_by",none)))[("blade_runner","directed_by","ridle_scott")] typeerror: list indices must integers, not tuple
the error getting unrelated triples
function. line in erroneous:
list(movie_graph.triples(("blade_runner","directed_by",none))) [("blade_runner","directed_by","ridle_scott")]
list(...)
returns list, , following square brackets, [...]
, attempting index list. list index must integer, not ("blade_runner","directed_by","ridle_scott")
, tuple, hence error seeing.
it's hard see trying achieve, that's why you're seeing error.
Comments
Post a Comment