# Choosing Condition File based on Participant's Number

**URL:** <https://discourse.psychopy.org/t/choosing-condition-file-based-on-participants-number/21730>\
**Category:** Online experiments\
**Tags:** pavlovia\
**Created:** [March 26, 2021, 3:11am UTC](https://discourse.psychopy.org/t/choosing-condition-file-based-on-participants-number/21730 "2021-03-26T03:11:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![westphal00](https://avatars.discourse-cdn.com/v4/letter/w/e5b9ba/32.png) [@westphal00](https://discourse.psychopy.org/u/westphal00)\
**Post date:** [March 26, 2021, 3:11am UTC](https://discourse.psychopy.org/t/choosing-condition-file-based-on-participants-number/21730/1 "2021-03-26T03:11:01Z")

</div>

Version: 2021.1.2  
OS: Windows 10

URL - [Learning\_1 [PsychoPy]](https://run.pavlovia.org/LernerLab/random/? __pilotToken=eccbc87e4b5ce2fe28308fd9f2a7baf3&__ oauthToken=52ad51f63afc49155d8d1496c0b8d227a305c383b3d933ca2451318355eac84a)

\*The code is set to piloting so I don’t know if the link will expire.

Description of the problem: I am trying to convert this string from Python into Javascript. The string chooses to use one of two condition files based on whether a participant’s number is even or odd. (Odd - List 1, Even - List 2). Below is the string in Python which works in the Coder.

trialList=data.importConditions(u’Practice\_List’ + str((int(expInfo[‘participant’]) % 2 \* -1)+ 2) +’.xlsx’),

And here is Psychopy’s translation into Javascript. I got this from putting the string in the custom code in the Builder.

trialList: importConditions(((“Practice\_List” + (((Number.parseInt(expInfo[“participant”]) % 2) \* (- 1)) + 2).toString()) + “.xlsx”));,

After inserting the string into the JS code and pushing it to Pavlovia, the code will only pick from condition list 1. Does anyone know what is wrong with it? Or have a simpler way of having the code choose?

Many thanks for any help!

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [March 26, 2021, 6:21am UTC](https://discourse.psychopy.org/t/choosing-condition-file-based-on-participants-number/21730/2 "2021-03-26T06:21:22Z")

</div>

For just two alternatives I would try if / else and remove the variable code from the import statements themselves

---

<div class="post-metadata">

**Author:** ![westphal00](https://avatars.discourse-cdn.com/v4/letter/w/e5b9ba/32.png) [@westphal00](https://discourse.psychopy.org/u/westphal00)\
**Post date:** [March 27, 2021, 8:53pm UTC](https://discourse.psychopy.org/t/choosing-condition-file-based-on-participants-number/21730/3 "2021-03-27T20:53:27Z")

</div>

Hi @wakecarter

Thank you for your response. This is what I have come up with but I am stuck getting an error.

# set up handler to look after randomisation of conditions etc

word\_loop = data.TrialHandler(nReps=1, method=‘sequential’,  
extraInfo=expInfo, originPath=-1,  
trialList= data.importConditions  
if(int(expInfo[‘participant’]) %2 == 0)  
(‘Practice\_List1.xlsx’)  
else  
(‘Practice\_List2.xlsx’),  
seed=None, name=‘word\_loop’)

The code produces the following error: " TypeError: ‘bool’ object is not callable". Do you know what this means and how to fix it?

Thanks

---

<div class="post-metadata">

**Author:** ![westphal00](https://avatars.discourse-cdn.com/v4/letter/w/e5b9ba/32.png) [@westphal00](https://discourse.psychopy.org/u/westphal00)\
**Post date:** [March 27, 2021, 8:54pm UTC](https://discourse.psychopy.org/t/choosing-condition-file-based-on-participants-number/21730/4 "2021-03-27T20:54:27Z")

</div>

Full error message: line 744, in   
(‘Practice\_List1.xlsx’)  
TypeError: ‘bool’ object is not callable

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [March 27, 2021, 10:21pm UTC](https://discourse.psychopy.org/t/choosing-condition-file-based-on-participants-number/21730/5 "2021-03-27T22:21:27Z")

</div>

That probable means you can’t call an if statement in the middle of defining a TrialHandler. Define a variable first and then use it.
