Cannot show Leading Zeroes in MSIT experiment

Hi there,
I just started using PsychoPy so sorry in advance if I sound too silly with my questions.
I would appreciate any specific details and instructions since I am very, very new here.

I’m trying to conduct an MSIT experiment using PsychoPy. This is an experiment that should present three digits, including those that begin with zeroes (e.g. 020, 003). I’m using mainly the builder and am importing the stimuli (i.e., the three digits) from an xlsx(Excel) file.

The problem is that the digits showing up on the screen does not include leading zeroes (e.g. showing 20, 3 instead of 020, 003).

Originally, my Excel file also did not present leading zeroes when I wrote the numbers. In order to solve this problem, I tried two methods and both of them worked for my Excel file.
First, I converted the cell data type from digits to text type. Another way was to change the cell style to “000” in a user defined data type.

Then, I tried the solutions suggested in Leading zeroes in text component which was to add $‘%03d’ % MY_VALUE in the text component. However, there was a syntax error.

To sum it up, all three digits show in the Excel file but not in the PsychoPy experiment screen.

Is there any way I can show the full three digits, starting with zero, on the screen?
Or perhaps there is a way I can use the abovementioned $‘%03d’ % MY_VALUE code?

My code from PsychoPy Coder are the following:

Loop2 = data.TrialHandler(nReps=1.0, method=‘random’,
extraInfo=expInfo, originPath=-1,
seed=None, name=‘Loop2’)
thisExp.addLoop(Loop2) # add the loop to the experiment
thisLoop2 = Loop2.trialList[0] # so we can initialise stimuli with some values

abbreviate parameter names if possible (e.g. rgb = thisLoop2.rgb)
if thisLoop2 != None:
for paramName in thisLoop2:
exec(‘{} = thisLoop2[paramName]’.format(paramName))

for thisLoop2 in Loop2:
currentLoop = Loop2
# abbreviate parameter names if possible (e.g. rgb = thisLoop2.rgb)
if thisLoop2 != None:
for paramName in thisLoop2:
exec(‘{} = thisLoop2[paramName]’.format(paramName))

# --- Prepare to start Routine "BlockList1_Control" ---
continueRoutine = True
# update component parameters for each repeat
Response2.keys = []
Response2.rt = []
_Response2_allKeys = []

Any ideas or solutions will be greatly appreciated! Thank you in advance.

Please could you clarify. If you put the code into an Auto translate code component then you may have seen a syntax error on the JS side if your code can’t be translated for online use, but that doesn’t necessarily mean it won’t work locally.


since you used the tag Builder I assume that you are using the builder to build your experiment instead of writing the code yourself. The following “code” should display numbers with a leading 0 off- and online.

I used an Excel-file to read the numbers, format is set to standard.

I defined a text-component in the Builder to display the number.


Notice the formatting of the string. The advice given in Leading zeroes in text component does not work online.

Best wishes Jens

Hello Wakecarter,

Thank you for the information. I tried to screen capture the “syntax error” and add it here, but the experiment works now so I cannot show how it appeared. But still, thanks for your reply!


Hello Jens,

Thank you so much for your reply. I really appreciate it.

The only problem is that our stimuli are the following(I am afraid I forgot to mention that in my post :frowning: ):
“100”, “020”, “003”

but if I use your code
“100” is presented as “0100”
“020” as “020”(which is great)
and “003” as “03”

because my Excel-file is written as

BUT your solution gave me an idea that I wanted to try out and thankfully, it worked!!
I tried using “Leading zeroes” code again($’%03d’ % Control), except this time, I used my Excel-file to read the numbers, BUT formatting it to standard. The name “Control” is the column name for the stimuli. (Hope this helps if anyone else is having the same issue)

Thank you so much for all your help!
All the best.