I've a field which is a string called name, the name I'm looking for is Cavia

Executing this on the python console gets no result, on the GUI gets the record selected. Therfore I'm doing some quotation error I can't figure out


layer.selectByExpression(' "name" = Cavia ', QgsVectorLayer.SetSelection)

  • 1
    Cannot test it right now, but try this: layer.selectByExpression(' "name" = \'Cavia\' ', QgsVectorLayer.SetSelection) – Germán Carrillo Jul 6 '19 at 2:10

Your Answer

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

Browse other questions tagged or ask your own question.