psychopy.org | Reference | Downloads | Github

Auto -> JS issue with string formatting

Hi. Am using Builder and Auto -> JS to try to design an online experiment. I believe I am getting an error in constructing a formatted string. In python I have

b_text = f'£{RB} in {DB} days'

where RB and DB are variables containing numbers. This is translated in JS as

b_text = `£${RB} in ${DB} days`;

I looked up and this seems to be the right way of building strings in JS, but I’m not sure. I am getting an error which I believe relates to this:

UnicodeEncodeError: 'ascii' codec can't encode character '\xa3' in position 0: ordinal not in range(128)

I downloaded and am using PsychoPy 2020.1.3 (although PsychoPy3 > About reports version 2020.1.2. Not sure if that’s a bug?)

That’s a Python error code, are you getting this error online or when running on your own computer?

I’m getting this error on my own computer. Looks like it was something to do with the “£” symbol rather than constructing the string itself. Removing the “£” solves the problem. Will find out how to print that in JavaScript

It may not be an issue in JS to start with. You’re right that it’s the £ symbol. Your best bet in JS, if it gives you trouble, may be to put the £ in whatever is defining the “RB” variable (which I assume is a conditions file?). Basically formatting strings on the fly can be dicey, but reading strings out of a condition file seems to be safer w/r/t symbols.

Also somewhat ironic that this has gone undetected given that it’s the currency symbol of PsychoPy’s country of origin.

RB will be a variable which is changed algorithmically depending on previous answers. I realised that running this locally will run the Python code, so I’ll see how far I get running it online. I’m still very new to the online experiment workflow.