1

I have this part of code inside a plugin:

Emptylist = []    
def saveToList(self, layer, EmptyList):
        for feat in layer.selectedFeatures():
            attributes = feat[self.pgLyr.currentText()]
            EmptyList.append(attributes)

when I run this code it stores attribute values to the list, but with additional information about the type of the field, so it returns (for example) u'387' if the field is text typed or L387 if the field is Long typed.

is there any way to get only 387 value, regardless of the additional information, without using a text splitting function?

1

python 2.7 method called encode("utf-8"), will do this easily:

Emptylist = []
def saveToList(self, layer, EmptyList): for feat in layer.selectedFeatures(): attributes = (feat[self.pgLyr.currentText()]).encode("utf-8") EmptyList.append(attributes)

it will change the encoding to utf-8 so the u'387' in unicode will be 387. nice and easy...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.