I would like to write a script that includes a selection from the attribute table. But my data is in Hungarian, so it includes special characters like: öüőűáéí

So when there is non of these in the query it executes, otherwise I get this:

Is there a setting or something to solve this?

  • 3
    Have you tried changing the layer's encoding to ISO 8859-2? You can change this by right-clicking your layer and going to Properties > General > Layer info > Data source encoding. The attribute table should show the characters correctly. Then test to see if your query works =)
    – Joseph
    Nov 30, 2016 at 11:21
  • No it did not work :(
    – buboreka
    Nov 30, 2016 at 14:02
  • Tell us what encoding you are using in this table and yours computer default encoding. It would be easier if you use UTF-8 everywhere, rather than local encodings like ISO-8859-2.
    – jgrocha
    Nov 30, 2016 at 15:12
  • 2
    Have a look at How Do I Stop the Pain? by Ned Batchelder.
    – jgrocha
    Nov 30, 2016 at 15:16
  • I'd like to solve this but within modeler. Is It possible ? Feb 19, 2019 at 10:21

1 Answer 1


What happens when you use diacritic characters?

It might be a simple python problem. Open the python editor in QGIS, and ensure that you start with the two comment lines on the top, like this:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
layers = QgsMapLayerRegistry.instance().mapLayersByName('utilizador') 
layer = layers[0]
it = layer.getFeatures()

for feat in it:
  layer.changeAttributeValue(feat.id(), 7, u'Jó napot kívánok!')

  • #!/usr/bin/env python # -- coding: ISO-8859-2 -- name = "Algyő" print name I did this in the console, but the result is still AlgyÅ
    – buboreka
    Nov 30, 2016 at 13:56
  • 2
    UTF-8 encoding is also good for Hungarian characters. The ISO-8859-2 is much older. You must know which of these two you are using.
    – jgrocha
    Nov 30, 2016 at 15:07
  • Well, as my ESRI shape is in utf-8 I started with that, than I give the ISO-8859-2 a try, but also did not help. But anyways, what really bothers me is that if I run that little code (also with utf-8) in any consoles it works but not here in qgis.
    – buboreka
    Nov 30, 2016 at 15:20
  • 1
    Did you try to prefix the strings with a u? u'Jó napot kívánok!' Nov 30, 2016 at 15:46
  • with the prefix it works in the console thank you! However I still have to find out how to use this in processing algorithm
    – buboreka
    Nov 30, 2016 at 16:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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