Using placeholders (%) in PsychoPy and PsychoJS

Hello.

I am attempting to translate a completed PsychoPy experiment to PsychoJS. When ever I try to use a placeholder (%), the JS will clear and read appx. ‘fix python code’. I know that the Python code works because we have run the experiments. I am not sure what in the Python might be breaking the translation to JS, however. Here is the Python function:

def saveToLog(logString):
    f = open(logFile, 'a')
    f.write(logString)
    f.write('\n')
    f.close()

Here is how I use the function in the Python code:


saveToLog('experiment: %s' % expName)
saveToLog('researcher: %s' % (metaData['researcher']))

Each of the implementations above will break the translation to JS as soon as I type the second ‘%’, e.g.


...% expName)

I know that JS uses placeholders quite a lot. Does anyone know why this seemingly basic feature or use of the placeholder may not translate into PsychoJS?

Thank you for your help.

Because there are many, many ways of formatting strings in Python and translating them to JavaScript could be improved I guess. You could make it easier by just using a form that I would think would get automatically translated better, because Python and JavaScript do it the same way:

'experiment: ' + expName

Or use a form of string formatting that that is closer to JavaScript string interpolation but may still require some manual manipulation on your part, e.g. a Python f string:

f'experiment: {expName}'

doesn’t take much manual tweaking to look like JavaScript interpolation:

`experiment: ${expName}`