Howdy, Stranger!

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

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.write('MoyOrtho\tMoyRime\tMoySém\tRepCorr\n')
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,

Comments

  • 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...

    Best

  • 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')

    Eduard

Sign In or Register to comment.