Between-subjects counterbalancing using Pavlovia (assigning different .xlsx conditions files to different participants)

Hi, I’ll be running an online psychopy experiment. I usually achieve between-subjects counterbalancing (of assigning stimuli to conditions, etc.) by loading a new excel conditions sheet for each participant. Presumably I can’t do this when I am running it online? Am I now forced to created different “versions” of my experiment for the different counterbalancing conditions? There must be a way around this, but I can’t seem to figure it out…

Thanks in advance!


This may help :slight_smile:

Hi Nicholas. In my case, I need to use a different conditions file for each participant (randomising the identity of the stimuli). Am I correct in assuming, that if I used your solution it may result in some condition files being selected more than once and others not being selected at all? Thanks!

I have a web app to help with this.



Hi, and thank you! Am I correct in understand that this requires me to ask the participant to enter an ID and/or link with Qualtrics? Is there a way to avoid both of those options?

They are designed to create a consecutive ID on the fly and do not need Qualtrics

Sorry for the silly question, but how do I label my condition files so that the ID generated matches a file? A related but somewhat similar question - have you seen the thread in Todd’s profile titled ‘personalising stimuli’? Out of curiosity, is that also a way to achieve the same end (randomise the identity of stimuli per participant, but in this case using one conditions file), and does it work online (the thread refers to builder). Thanks!

How many different conditions files do you have? I would label them something like condition0.xlsx, condition1.xlsx, etc. and then use

useFile = "condition"+str(expInfo['participant']%8)+".xlsx"

if you have 8 different files.

Thank you for the specific instruction! I’ll probably end up using 40 condition files. I will use your suggestion. The reason for my second question was just to understand different ways of doing things.

Any insight why I would receive the following message: ‘TypeError: not all arguments converted during string formatting’.

Please could you copy and paste (into preformatted text) the line that you think isn’t working?

The error referred to this line in the code: useFile = “condition”+str(expInfo[‘participant’]%2)+".xlsx"

I’m testing our discussed solution using 2 conditions files (condition0.xlxs; condition1.xlxs) and running it locally.

Also - when running it online through your app - the experiment opens and goes through the welcome page, but then gives the following error:

  • when importing condition: condition1.xlsx
  • when getting the value of resource: condition1.xlsx
  • unknown resource

Have you copied the Excel files to html/resources ?

Hello, I am trying to implement this but where exactly should I paste this code?

All the best,


Which code?

I put useFile = “condition”+str(expInfo[‘participant’]%8)+".xlsx" in Begin Experiment

Note that this thread is old and the advice to copy files to html/resources is no longer relevant.

1 Like

Thanks ! I’m trying to use your method here but because I’m a beginner I’m struggling a bit.

So far I understand how to structure my URL but I don’t know how to specify things in PsychoPy.

Is useFile = “condition”+str(expInfo[‘participant’]%8)+".xlsx" in Begin Experiment enough to make it work? does it achieve the same thing as condition = int(expInfo['participant'])%x as indicated on your web app?

Do I have to include code in PsychoPy to register the participant ID or does your web app do that automatically?

All the best,


I’d need to know more about your PsychoPy experiment to answer this but yes, those two codes are doing equivalent things: one is selecting a conditions file called condition0.xlsx to condition7.xlsx (which would also need to be added in Experiment Settings / Online / Additional Resources. The other is setting condition as a number from 0 to x-1.

participant and session are read by default by PsychoPy experiments, unless you edit/delete these variables in Experiment Settings

1 Like

Thank you ! Regarding my experiment, I think it is very similar to what previous posters have described here : I have an experiment that counterbalances the stimuli between subjects across 18 distinct sets (so, 18 distinct Excel files).

I’ll try this all out and let you know. I may have one last question though. If, for instance, I’ve had 18 participants click on my URL and they have gone through the cycle of the 18 conditions, what will happen when a 19th participant clicks? Does it automatically go back to condition 1 ?

If you use %18 then participant 0 and participant 18 will see then same Excel file.

If you would prefer random balanced allocation rather than cycling through systematically, then you should use my VESPR Study Portal. Licenced users (£10) can have a variable called group which is randomly allocated but counterbalanced and adjusts for non-finishers.

1 Like