Can't append str to lst after upgrading to OpenSesame v4
Hi mods,
Hopefully only a silly/quick question but I'm stumped - in some code that worked in v3, I split up sentences and iteratively append the words to an empty list called var.stimuli
so that they are presented to participants one at a time (RSVP for EEG experiment; code snippet below). After upgrading OpenSesame to v4, I now get the error AttributeError: 'str' object has no attribute 'append'. I have confirmed that var.stimlui
is a list and the word to append is a string, and it works to do this manually in the console, but for some reason returns the error when I run the inline script. Are lists and strings somehow handled differently in the new OpenSesame? The only clue is that when I print the word from the loop (w
below), the output is e.g. the
instead of 'the'
(i.e. no quotes around it). Is that odd, even if it type()
returns str?
Many thanks, Kate
# list to store words var.stimuli = [] # function to split up sentences into words def stim_prep(stims, trigger = "n"): stims = stims.split() for i, w in enumerate(stims): if(trigger == "y"): send = i + (var.cond + 1) * 10 else: send = 0 print(w) print(type(w)) print(stimuli) print(type(stimuli)) var.stimuli.append(w) # <--- error occurs here print(stimuli) word_canvas = canvas() word_canvas.text(w) word_canvas_list.append(word_canvas) var.pres_dur.append(pres_dur(w)) var.trigger.append(send) return;
Comments
Update: It's something to do with using
var.stimuli
versusstimuli
in thestim_prep
function. If I usestimuli
, it works fine, but then obviously it's not logged in the log file, which I would like. But it doesn't seem to recognise the pre-definedvar.stimuli
.I've attached the whole experiment in case it's helpful.
stim_prep
is in the "settings" inline script andvar.stimuli
is defined in the RSVP/prepare inline script (I tried moving everything to the RSVP/prepare script and the same problem happened).Hi Kate,
I think this has to do with this change in OS4: https://osdoc.cogsci.nl/4.0/notes/400/#important-backwards-incompatible-changes
So, a list is not stored as a list anymore. To still include it in the logger, you can explicitly add it to the logger.
Alternatively, it might work for you to not store the stimuli in a list but in a string, where each item is separated by the same character, so that during the analysis you can easily re-generate the list.
For example:
Hope this helps,
Eduard
Hi Eduard,
Thanks very much for this, it makes a lot of sense and will work!
Best,
Kate