Howdy, Stranger!

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

Supported by

"list index out of range" when running exp, but can't find error in inline script

Hello,

I have an experiment file full of inline scripts that probably look like a pig's breakfast seeing as I'm not used to working with Python. When I check the inline scripts by copy-pasting their content into the console, everything works as it should. However, when I run the experiment using the Run command, I get the following error:

Starting experiment as ExperimentProcess-1
Expyriment  (Python 2.7.14) 
openexp.sampler._legacy.init_sound(): sampling freq = 48000, buffer size = 1024
experiment.run(): experiment started at Wed Apr 18 14:11:07 2018
experiment.run(): disabling garbage collection
Traceback (most recent call last):
  File "/usr/lib/python2.7/multiprocessing/queues.py", line 268, in _feed
    send(obj)
TypeError: expected string or Unicode object, NoneType found
experiment.end(): enabling garbage collection

Error while executing inline script

item-stack: experiment[prepare].construct_adaptation_reliable[prepare]
exception type: IndexError
exception message: list index out of range
item: construct_adaptation_reliable
time: Wed Apr 18 14:11:08 2018
phase: prepare

Traceback:
  File "/usr/lib/python2.7/dist-packages/libopensesame/inline_script.py", line 77, in prepare
    self.experiment.python_workspace._exec(self.cprepare)
  File "/usr/lib/python2.7/dist-packages/libopensesame/python_workspace.py", line 174, in _exec
    exec(bytecode, self._globals)
  Inline script, line 202, in <module>
IndexError: list index out of range

I consistently get this error when using Run, but never when going through the inline scripts line by line. I tried changing the offending lines, but that didn't work. I've no idea how to fix this error or what's causing it. I've attached the experimental file as well as a file containing the stimuli to be read in (you'll need to rename them to osexp and csv, because the interface didn't let me upload them otherwise); any help would be greatly appreciated.

Specs:

  • OpenSesame 3.2.4b1
  • Python 2.7.14
  • Ubuntu 17.10

I couldn't replicate this error on Windows as the experiment throws another error (Python crashed. This shouldn't happen etc.)

Comments

  • edited April 2018

    Please ignore, I think I'm getting there. While I'm still not sure why the problem didn't crop up when manually going through the code, I'm now literally copy-paste every line of the inline script and using the print() command to see where things go awry.

    Edit: I've solved the problem. It's a bit too specific to be of any use to anyone else, I think, but in essence the error occurred because elsewhere, the script sometimes did and sometimes didn't create an empty array. Whenever an empty array was created, this resulted in the "list index out of range" error several lines below. I still don't know why this never happened in the 10+ times I went to the script manually, but I eventually found the problem by building up the script line by line and checking the result of each line using "print(newly_created_variable)". HTH

Sign In or Register to comment.