How to select attributes by unicode field value?

المشرف العام

Administrator
طاقم الإدارة
I have an attribute table in QGIS 2.10 with a string field (myfield) and when I want to make a selection based on the unique values of this field I get no selection at all.

>idxmyfield = mylayer.fieldNameIndex("myfield")>uniquevalues = mylayer.uniqueValues(idxmyfield)>uniquevalues>[u'avalue', u'bvalue']>type(uniquevalues[0])>>y = len(uniquevalues)>for x in range(y): it = mylayer.getFeatures(QgsFeatureRequest().setFilterExpression (u' "myfield" = {0}'.format(myfield[x]))) mylayer.setSelectedFeatures([f.id() for f in it]) selection = mylayer.selectedFeatures()If I use another field with integer values the code is working. But if the values of the field are unicode/string it is not selecting anything.

So the type unicode differs from string or is it a type of string? If so, how can I change the type from unicode to string? Or how do I need to change the expression in order to get the selection I want?



أكثر...
 
أعلى