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