Experiment Crashing Due to Error (saveAsText error)!

OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): v2023.3
Standard Standalone? (y/n): y
What are you trying to achieve?: offline

pilot_legacy.psyexp (83.5 KB)
pilot_lastrun.py (80.2 KB)
pilot_legacy.psyexp (83.5 KB)

My experiment was working properly; however, after I added 3 breaks for when a certain this
N was reached using a code component in the end routine of the last routine in the loop (see below), it started crashing after trial 28 (there were 29 trials in total). I had to use code instead of other ways because it was working for assigning the participant to Excel depending on the ExpInfo (5 lists), randomising the stims in that Excel file and retrieving the correct image to display (no repeats).

if Conds.thisN == 12:
break_msg = visual.TextStim(win=win, text=‘Well Done! You are halfway done! Time for a break.’, pos=(0, 0), height=0.05, wrapWidth=None, ori=0.0,
color=[-0.1765, -0.1765, -0.1765], colorSpace=‘rgb’, opacity=None, languageStyle=‘LTR’, depth=0.0)
break_msg.draw()
win.flip()
event.waitKeys()

elif Conds.thisN == 21:
break_msg = visual.TextStim(win=win, text=‘Well Done! You are nearly done! Time for a break.’, pos=(0, 0), height=0.05, wrapWidth=None, ori=0.0,
color=[-0.1765, -0.1765, -0.1765], colorSpace=‘rgb’, opacity=None, languageStyle=‘LTR’, depth=0.0)
break_msg.draw()
win.flip()
event.waitKeys()

if Conds.thisN == 29:
break_msg = visual.TextStim(win=win, text=‘Well Done! You have finished the task. We will now count your coins, you will recieve your gift as soon as possible! Thank you’, pos=(0, 0), height=0.05, wrapWidth=None, ori=0.0,
color=[-0.1765, -0.1765, -0.1765], colorSpace=‘rgb’, opacity=None, languageStyle=‘LTR’, depth=0.0)
break_msg.draw()
win.flip()
event.waitKeys()

What did you try to make it work?:

  • I removed code (from break_msg.draw()) to see if that would help. I also tried using this code out of the if statement.
  • I also tried removing all the code, just keeping the text and creating a routine ($break_msg). However, this did not work because the routine couldn’t be in the loop, so thisN did not work
  • I had one if statement with all the trial breaks, e.g., [6,12, 21]
  • I included continueRoutine and then continueRoutine = False for the 29, same problem.
  • at the start, I did not have the last code (for 29) and instead had an end routine, so I tried removing that and adding it to the code instead.
    I also changed where I put the code, including different routines in and outside the loop and where in the code component, e.g., the start routine, the start of the experiment, and the end routine.

I can’t think of anything else!

What specifically went wrong when you tried that?:

What happens (depending on how I attempt it) is that the breaks work, but then at 28 trials (29 trials in the Exp, then the end screen), it crashes. Then it has the code below, which is the same no matter how I do this.

Conds.saveAsText(filename + ‘Conds.csv’, delim=‘,’,
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\data\base.py”, line 201, in saveAsText
dataArray = self._createOutputArray(stimOut=stimOut,
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\data\trial.py”, line 423, in _createOutputArray
strVersion = str(tmpData.tolist())
TypeError: repr returned non-string (type tuple)


pilot_lastrun.py file

It appears this is where it goes wrong, but I don’t even know why this code is here. Btw, it does save all output, but appears, to stop when the crash happens.

get names of stimulus parameters
if Conds.trialList in (, [None], None):
params =
else:
params = Conds.trialList[0].keys()
# save data for this loop
Conds.saveAsText(filename + ‘Conds.csv’, delim=‘,’,
stimOut=params,
dataOut=[‘n’,‘all_mean’,‘all_std’, ‘all_raw’])

@Becca @wakecarter

Can either of you advise on this issue? I can’t find any information to know why this is happening or how to fix it. If so, much appreciated :slight_smile:

I have tried changing the code completely, but I still get the same error. I couldn’t find any information on why this error would happen (e.g., what I’ve done or how to fix it). It doesn’t allow me to finish the exp so i really need to fix it.

Please help.

trials.saveAsText(filename + ‘trials.csv’, delim=‘,’,
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\data\base.py”, line 201, in saveAsText
dataArray = self._createOutputArray(stimOut=stimOut,
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\data\trial.py”, line 423, in _createOutputArray
strVersion = str(tmpData.tolist())
TypeError: repr returned non-string (type tuple)

What I did to try and fix it based on our threads.

in the same routine, end routine code component

  • if trials.thisN == 0 or trials.thisN % 6!= 0:
    trials.finished = True
  • Added in a routine called break with text (‘Time for a break! Press Space to continue’) and a loop to continue the task after the break text.

Okay, so the breaks are now working, but still getting the same error!

current task: I moved the text component (renamed tbreak) to inside the loop in the Feedback routine instead, made sure it updated every frame and added the code below to each frame in the code component. This text component combined with my code (code_4) shows ‘Time to take a break!’ for each 5,15,20,25. When it is not there, the text is invisible.

Current code:

if trials.thisN not in [5, 15, 20, 25]:
tbreak.opacity = 0
else:
tbreak.opacity = 1

Debug error: @jon @Becca @wakecarter Please help, I have no clue how to fix this error, but I have tried creating a whole new psychopy task and still getting the same issue. Why? Does anyone know? Is it something wrong with the task, or my Psychopy or Psychopy itself???

91.1356 DEBUG Saving data for pilot_test ExperimentHandler
trials.saveAsText(filename + ‘trials.csv’, delim=‘,’,
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\data\base.py”, line 201, in saveAsText
dataArray = self._createOutputArray(stimOut=stimOut,
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\data\trial.py”, line 423, in _createOutputArray
strVersion = str(tmpData.tolist())
TypeError: repr returned non-string (type tuple)

Hi There,

To help us guide here, please could you try to strip your experiment back to the most basic level at which you can replicate the error (i.e. remove routines and components gradually until you find the moment where the error does occur or does not occur).

Some things I noticed looking at your .psyexp (but I don’t know if they are relevant to the current error).

  1. There are alot of import statements in code that are not needed. For example from psychopy import data - these are automatically imported by PsychoPy, if you compile your experiment to a python script :compile_py: then you can see the libs imported automatically at the top of the script.
  2. I noticed your experiment uses a mic component, does the error happen without the mic component? (incase the error is to do with saving transcripts.
  3. I noticed that you have Save csv file (summaries) selected in the experiment settings :experiment_settings: > Data tab, does the error happen if that is unchecked (incase the error is to do with saving the summary).

My gut is that it is arising from saveAsText which is to do with point 3

Thanks,
Becca

1 Like

pilot_test_lastrun.py (82.3 KB)
pilot_test.psyexp (66.9 KB)
pilot_test.py (82.3 KB)

Thank you so much, Becca, for responding.

Hi @Becca. I managed to get it to do all the trials (by setting it to 0-30 trials in the loop) and save all the data without crashing, though I am still not sure if it is a quick fix (and it only works if i do not select summaries).

  1. I realised this and immediately removed them.
  2. Before I introduced the breaks (e.g., the code mostly), the mic was working perfectly, and so was everything else.
  3. You were right about 3. The issue persists whenever I select summaries. If I de-select, it is no problem.

Is this something I need to fix, or can I get away with it? Why do you think this is happening?

Hi Hans,

I am not sure I know what is causing that issue at the moment, it might be a bug we were not aware of so I can look into it. For now I would suggest not using the summaries unless you absolutely need them. Perhaps use a code snippet to save average times etc to your existing data file.

Becca

1 Like