1

I tried to copy all features in a list of dictionaries. The code looks as follows:

def iterate_features(self):
    feature_set = arcpy.SearchCursor(self.address)
    for feature in feature_set:
        yield feature

def create_new_dict(self):
    iterator = self.iterate_features()
    if u"Matched_to" not in self.fieldList[:]:
        #arcpy.AddField_management(input_data, u"Matched_to", "TEXT")
        for item in iterator:
            feature = dict()
            for f in self.fieldList:
                feature[f] = item.getValue(f)
            feature[u"Matched_to"]=[]
    else:
        for item in iterator:
            feature = dict()
            for f in self.fieldList:
                feature[f] = item.getValue(f)
        self.new_features_dict.append(feature)

Now that I want to fetch the Matched_to list, what it returns is a Unicode object instead of a list. Hence I cannot append anything to it. Moreover, the field Matched_to is added to the shapefile without being updated or edited. I think it has something to do with shallow and deep copy but I don't know how and where to implement it.

closed as unclear what you're asking by PolyGeo Sep 27 '16 at 5:06

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    Can you edit your question and give some background info for why you are copying features in a list of dictionaries? – artwork21 Jul 2 '14 at 15:44