Insert multiple spaces in text

URL of experiment: ZeitVari [PsychoPy]

Description of the problem: I am programming a flanker experiment in which flanker precede the target by some time. To achieve this it create tow stimuli, one without the target, the other with the target. I use the following code to create the stimuli.

nSpace = (Target.length + 2);
prime = (((("|" + Flanker) + (" ".repeat(nSpace))) + Flanker) + "|");
target = (((((("|" + Flanker) + " ") + Target) + " ") + Flanker) + "|");

While this code works on Win-computer, it does not run reliably on Macs. The prime stimulus does not contain the proper number of spaces. Any suggestion how to compute and insert the proper number of spaces in the stimulus?

Best wishes Jens

Are you presenting in Courier New?

Do you think the issue is repeat(nSpace) ? If so, you could try

nSpace = ' '
for Idx in range(len(Target)):
     nSpace += ' '

Then use + " " + nSpace + " " + in the code

Please use an auto translate component to translate my Python to JS.

1 Like


I am using Consolas as font. I already tried another font because I thought that the error was font-related. But it did not help and the font was installed on the laptop anyway.

Thanks for the code. I give it a try. But I don’t have easy access to Macs, so it may take some time to report back.

The behaviour is also inconsistent across Macs. The code doesn’t fail on all Macs.

.report should work in current browsers according to its documentation…

Best wishes Jens


I had access to a Mac and was able to test the code provided by @wakecarter. Unfortunately, it does not work. I tried Chrome and Safari on the Mac and an iPad. Any idea how to proceed?

Best wishes Jens


ok, the error was due to the chosen font, Consolas. The loop-code works with Courier New. I did not yet try whether the .repeat would work as well with Courier New.

This is really strange. Consolas is a non-proportional font for Win since 2007 and MacOs since 2008, at least according to the German Wikipedia. It should replace Courier New. It is not mentioned in the English Wikipedia as part of MacOs. So, I assume that Consolas is not installed per default on Macs. On Macs it might come with MS-Office.

Best wishes Jens