Sign in with your CogSci, Facebook, Google, or Twitter account.

Or register to create a new account.

We'll use your information only for signing in to this forum.

Supported by

Use variable in OpenSesame

Hi Sebastiaan and all,

I'm stuck in a simple problem. I want to save my data in my own file as I want the experiment to be done several times by the same subject and I would like is datas to be appended in the same file.

In order to do that I would like to save a file with my subject number.
So I tried things like:
import os
path = exp.experiment_path + "/results." + var.subject_nr + ".txt"
myfile = open(path, 'a') # Open for output (creates).
myfile.close( )

But this part
path = exp.experiment_path + "/results." + var.subject_nr + ".txt"
is wrong.

Would you have any idea of the problem, please ?

Best regards,


  • borisboris Posts: 60

    Finally I used the old variable access solution and it's working:
    path = exp.experiment_path + "/results." + str(self.get('subject_nr')) + ".txt"

    But I don't understand why the new way (str(var.subject_nr)) is not working...


  • eduardeduard Posts: 1,170
    edited January 2017

    Hi Boris,

    Two things for sakes of completeness.

    1) var.subject_nr returns an integer. You can't concatenate integers with strings. So if you had used str(var.subject_nr), it would also have worked.

    2). To create paths, you better use the os library (which you already import but never actually use). Doing this makes the creation of concatentated paths easier and platform independent:
    path = os.path.join(exp.experiment_path, 'results'+str(var.subject_nr)+'.txt')


Sign In or Register to comment.