[solved] Danish language?
Hi,
I built a questionnaire in Opensesame and it works fine in Dutch and English. Now we would like to send it to a collaborator in Denmark, but I get this error:
Python traceback:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 18: ordinal not in range
Is it not possible to use the Danish letters?
thanks Mona
Comments
Hi Mona,
Generally speaking, a
UnicodeDecodeErroroccurs when you are working with text that contains special characters (like Danish, which uses accents like 'ø'), but don't explicitly specify your text encoding. OpenSesame should be unicode-safe, but if you write your owninline_scriptitems, you have to take care not to trigger these errors. It can be tricky stuff.I would first take a look at the full error message, which you can find in the debug window. This should tell you whether it's triggered by an
inline_script(I suspect so), or by OpenSesame itself. If the latter is the case, it's a bug. But either way, please post the full error message and (if any) theinline_scriptthat caused it.Cheers,
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Hi Sebastiaan,
thank you for your nice reply
It indeed has to do with the inline script. It works up until I change the name of the questions into Danish.
In a normal text display it works fine, indeed.
Mona
the 'stripped' code that gives the error after including Danish letters:
for the questions:
to build the questionnaire:
to log name of question:
Python traceback:
Hi Mona,
The problem is the logging part, here:
You're running into a pretty tricky aspect of Python, which causes a lot of trouble for a lot of people. Basically, if you define a
str(e.g.,s = 'my str'), Python doesn't know what the character encoding is, and--unless you explicitly tell Python otherwise--assumes that it isascii, which doesn't contain any special characters. This is weird, because you can see the special characters in the editor, but nevertheless Python doesn't know how to deal with them.To work around this in a more-or-less reliable way you should use the
unicodetype, like so:The difference in notation is the little
uin front of the text, but this makes all the difference. You now declare the text in a non-ambiguous way, i.e. in a such a way that Python knows how to deal with special characters.This is a really tricky subject, which is explained reasonably well here:
But for now, I would simply recommend always using
unicodetext ininline_scriptitems. As a general (but non-fool-proof) rule this works best.Cheers!
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Perfect! All that was between me and the solution was a little "u"

Thank you so much for the great help!
Now we can send the questionnaire (and open sesame) to Denmark!
Mona