Outputting a readable conditions file, no solution?

If this template helps then use it. If not then just delete and start from scratch.

OS (e.g. Win11):
PsychoPy version (e.g. 1.84.x): 2022.2.2
Standard Standalone? (y/n) y
What are you trying to achieve?:
I am attempting to output a file after a loop has run which has a readable conditions file format using either the MultiStairHandler or ExperimentHandler so that it be used as a conditions file in a successive loop.

What did you try to make it work?:
I can successfully output files as xlsx, or txt

What specifically went wrong when you tried that?:
When i export the xlsx file there are space-separated headers. Upon attempting to read this file as a conditions file i get the following error:
Parameters (column headers) cannot contain punctuation or spaces

When i export using ExperimentHandler, i get the following error:
UnboundLocalError: local variable 'trialList' referenced before assignment
This may be an issue with the encoding: Unix (LF). Whereas, excel files typically use Macintosh (CR), i believe.

I have also tried to just point to the output file for the loop using conditions = $threshold_file

Thank you

How exactly do you export the xlsx?

By “space-separated headers” do you mean there are spaces in the cells of the header? I do understand this phrase in the context of txt files but not xlsx files.

I export xlsx as per the documentation for multistairhandler.

There are spaces between the texts in the header. I.e. “All Reversals” instead of “All_Reversals”

I am not really sure what you are trying to achieve here, but what you could do is after writing the file, open it again with some Python code, change the headers to not contain spaces, and write the file again. Then you should in principle be able to read it as a conditions file.

This might be a starting point (not tested):

import xlwt
import xlrd
from xlutils.copy import copy
# load the excel file
rb = xlrd.open_workbook('YourFile.xlsx')
# copy the contents of excel file
wb = copy(rb)
# open the first sheet
w_sheet = wb.get_sheet(0)
# modify cell values
for j in range(0, w_sheet.ncol - 1):
   w_sheet.write(0,j, w_sheet.cell_value(0, j).replace(" ","") )
# save the file