[open] Is it possible to save variables to a file outside of the logger?
Hi there! This is a follow up post to my earlier one from last week
The short version:
With help of this site I was able to import a text file as a string of words, store it as a python variable called word_list using numpy, randomize the list, and loop through it to present each word on a screen. I then stored the words as an experiment variable [word]. My only issue now is that when I try to reuse this python variable word_list in a different loop later on, OpenSesame no longer recognizes the python variable word_list. I tried globalizing word_list but that did not seem to work either.
I was wondering if it is possible to store the words presented on the screen from the first loop in a new text file (not the logger) and reread this into the second loop. It is very important that I can gain access to the exact same words because the subjects are being tested on them. (Study phase in the first loop, test phase mixed with old and new words in subsequent loops).
I appreciate the help I have received from this forum!
Thank you ![]()
Comments
Hi,
If you want to write your words to a temporary file, you could do this as follows. First, before the training block, open a file (
my_file) in write mode.At the end of the trial, write the current word to the file. Here we assume that this word is stored as an experimental variable with the name
word. Note the\ncharacter. This a line separator, which you need to explicitly add to avoid getting a single long line of text.Then, after the training block is finished, close the file.
So that's quite easy, really. For more information about files in Python, see:
That being said, wouldn't it be even easier to store the words in a
list? Then you would create an empty list before the training block ...... and add the words like this ...
Both methods are possible, but the
listway is a bit simpler.Cheers!
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Thank you again! The only issue I keep having is that when I create a new inline code in my second loop, OpenSesame no longer recognizes my_list and tells me it doesn't exist (the red arrow appears while typing- 'undefined my_list'). Is placement within loops the issue? Where should I place all this code? Also, when I save word to a temporary file, it only loads the very last word of the sequence and that word alone.
Would it be more helpful if I outlined my experiment?
The code validation only checks
inline_scripton their own. Therefore, if you refer to names that have been defined elsewhere you will get a warning. But unless you actually experience a crash, that's no problem. You can disable validation in the preferences of the editor component. (It's disabled by default as of 2.9.0, for precisely this reason.)Check out SigmundAI.eu for our OpenSesame AI assistant!