Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

[solved] Danish language?

edited June 2014 in OpenSesame

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

  • edited 1:30AM

    Hi Mona,

    Generally speaking, a UnicodeDecodeError occurs 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 own inline_script items, 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) the inline_script that caused it.

    Is it not possible to use the Danish letters?

    image

    Cheers,
    Sebastiaan

  • edited May 2014

    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:

    Question_number1 = "Jeg tænkte på andre"
    

    to build the questionnaire:

    from libopensesame import widgets
    form = widgets.form(self.experiment, cols=[2,1], rows=[1,1,1,1,1,1,1,1,1,1,1,1])
    question01 = widgets.label(form, text=Question_number1, center=False)
    form.set_widget(question01, (0,rows[0]))
    form._exec()
    

    to log name of question:

    self.log('Question1 = "Jeg tænkte på andre"')
    

    Python traceback:

    inline_error: Error: Inline script error
    In: inline_10 (run phase)
    File "libopensesame/item.pyc", line 989, in log
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 18: ordinal not in range(128)
    
  • edited 1:30AM

    Hi Mona,

    The problem is the logging part, here:

    self.log('Question1 = "Jeg tænkte på andre"')
    

    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 is ascii, 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 unicode type, like so:

    self.log(u'Question1 = "Jeg tænkte på andre"')
    

    The difference in notation is the little u in 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 unicode text in inline_script items. As a general (but non-fool-proof) rule this works best.

    Cheers!
    Sebastiaan

  • edited 1:30AM

    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

Sign In or Register to comment.