psychopy.org | Reference | Downloads | Github

UnicodeDecodeError in linguistics experiment, occurs after adding test conditions spreadsheet

Hi everybody,

currently I am creating an experiment in Psychopy. Now I have included two code components which contain variables I use for counting.
I define these as integer 0 under ‘Begin experiment’:

japvStimper = 0
nojapvStimper = 0
chosen_text2 = 0

noStimper2 = 0
audioStimper2 = 0
chosen_sound2 = 0

Then I programmed ‘if conditions’ because two variables should vary. The variables that are supposed to vary half/half are japvStim and nojapvStim. The conditions file has 10 rows in total, thus neither of my variables should be picked more than 5 times.

# choose one of the two variables:
chosen_text2 = np.random.choice([japvStim, nojapvStim])

if japvStimper < 5 and chosen_text2 == japvStim: 
    japvStimper = japvStimper + 1
else: 
    chosen_text2 = nojapvStim

if nojapvStimper < 5 and chosen_text2 == nojapvStim: 
    nojapvStimper += 1
else: 
    chosen_text2 = japvStim
    japvStimper += 1

When I try to run my experiment now, I get this error:

Running: /Users/reinhard/Desktop/Experiment/myexp4_lastrun.py

File “/Users/reinhard/Desktop/Experiment/myexp4_lastrun.py”, line 78
Traceback (most recent call last):
File “/Applications/PsychoPy2.app/Contents/Resources/lib/python2.7/psychopy/app/builder/builder.py”, line 2022, in onProcessEnded
self.stdoutFrame.write(text)
File “/Applications/PsychoPy2.app/Contents/Resources/lib/python2.7/psychopy/app/stdOutRich.py”, line 134, in write
self.stdoutCtrl.write(text)
File “/Applications/PsychoPy2.app/Contents/Resources/lib/python2.7/psychopy/app/stdOutRich.py”, line 62, in write
self.WriteText(thisLine)
File “/Applications/PsychoPy2.app/Contents/Resources/lib/python2.7/wx/_core.py”, line 13092, in WriteText
return core.TextEntryBase_WriteText(*args, **kwargs)
UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xef in position 4: ordinal not in range(128)

It seems like I only get this error once I include the two code components above and my conditions.xlsx for my actual test items. Everything worked fine before, even when I used my training items together with the two code components above (only 4 rows, different conditions spreadsheet).

How can I fix the Unicode error? I tried using an older version, Psychopy 1.85.2 to no avail.
Or do I need to convert my variables to integer? I can’t see where this error related to strings occurs… (I’m rather new to Python, so I am rather a layman, please be gentle :wink: ).

Thank you very much in advance!

What does

File “/Users/reinhard/Desktop/Experiment/myexp4_lastrun.py”, line 78

contain?

It contains “japvStimper = 0”. Here I define the variable which I use to count the number of instances “japvStim” was picked by the random function.

Here is the context:

# Initialize components for Routine "instr"
instrClock = core.Clock()
text = visual.TextStim(win=win, name='text',
    text=u'Hallo, willkommen zu meinem Experiment! Dr\xfccke die Leertaste um zu beginnen! ',
    font='Arial',
    pos=(0, 0), height=0.1, wrapWidth=None, ori=0, 
    color='white', colorSpace='rgb', opacity=1,
    depth=0.0);

# Initialize components for Routine "JapStim"
JapStimClock = core.Clock()
japvStimper = 0
nojapvStimper = 0
chosen_text2 = 0
noStimper2 = 0
audioStimper2 = 0
chosen_sound2 = 0
text_2 = visual.TextStim(win=win, name='text_2',
    text='default text',
    font='Arial',
    pos=(0, 0), height=0.1, wrapWidth=None, ori=0, 
    color='white', colorSpace='rgb', opacity=1,
    depth=-2.0);
text_3 = visual.TextStim(win=win, name='text_3',
    text='default text',
    font='Arial',
    pos=(0, 0), height=0.1, wrapWidth=None, ori=0, 
    color='white', colorSpace='rgb', opacity=1,
    depth=-3.0);
sound_1 = sound.Sound('A', secs=-1)
sound_1.setVolume(1)
sound_2 = sound.Sound('A', secs=-1)
sound_2.setVolume(1)

Was anyone able to resolve this issue? I’m running into a similar error but using SaveAsWideText where the stim file includes character text.