Can I get the conditions file name/path in code component?

Hi there,

I would like to have the file name of the conditions file in a variable in a code component. I would like to write it into the trials data csv-file for logging purposes.
I looked into the python code which is generated by PsychoPy and there I find it only hardcoded.

Cheers

Hi,

If I haven’t misunderstood what you would like to achieve, you could create a code component like this:

inputFile="myInput.xlsx"
thisExp.addData("input", inputFile)

And then add $inputFile as conditions file in your loop.

Hope this helps.

Tom Ate

Thanks,

yes that would work, but it’s not what I would really like to have. I am using the normal way in the builder to specifiy the conditions file and paste the path of the file in the loop parameters. So I have a hard coded conditions file name in the builder. What I would like to have is getting that file name into a code component. I would like to read it into a variable. I don’t know if that’s possible because in the python code generated by PsychoPy, the conditions file name is hard coded as well and I think it’s not saved in a variable - only the content of the conditionsfile is.

Cheers

Yes, it looks like you are right: the TrialHandler object only seems to store the contents of the conditions file, not the name of the file itself.

One way around this is to make a column in your conditions file that actually contains the file name. It’s inefficient, as you’re specifying the name of the file multiple times (once per trial), but it does mean that the filename becomes available to you to use as a variable like any other.

Thank you Micheal,

this is actually not a bad idea. It looks strange in the conditions file and in the trials data but it’s the same with the session and partissipant number anyway.

Cheers

Actually, there is a way to achieve this more directly.

Instead of putting the condition file name in the loop dialog, add a field to the experiment info dialog that appears before each experiment and insert the name of the conditions file there ( if required, add additional fields for other conditions files). For example, you could add a field called loop_1_conditions and put the .xlsx or .csv filename in there. Then in the loop dialog you can access that field’s content by putting this in its Conditions field:

$expInfo['loop_1_conditions']

You can also access the file name in a code component using the same expression (without the $ symbol).

Hallo Michael,

interesting idea but for practicality reasons I will stick to the solution with the extra column in the conditions file. At the moment I have 32 psypy files and I just don’t want to fill in an extra field every time I run an experiment.

Cheers

Really? I’m guessing you mean .psyexp files. If so, there really is quite an issue there that I’m sure could be resolved in a simpler way.