# Select a specific row of the conditions file inside a loop

**URL:** <https://discourse.psychopy.org/t/select-a-specific-row-of-the-conditions-file-inside-a-loop/33741>\
**Category:** Builder\
**Created:** [March 9, 2023, 4:23pm UTC](https://discourse.psychopy.org/t/select-a-specific-row-of-the-conditions-file-inside-a-loop/33741 "2023-03-09T16:23:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![miguelpostema](https://avatars.discourse-cdn.com/v4/letter/m/c0e974/32.png) [@miguelpostema](https://discourse.psychopy.org/u/miguelpostema)\
**Post date:** [March 9, 2023, 4:23pm UTC](https://discourse.psychopy.org/t/select-a-specific-row-of-the-conditions-file-inside-a-loop/33741/1 "2023-03-09T16:23:52Z")

</div>

Hi all,

I am using PsychoPy v2022.2.4 on macOS Ventura Catalina 10.15.7 (19H2026).

In my experiment, the participant has to study a concept and its definition, and can choose between three options: (1) re-read the concept and definition, (2) try to retrieve the definition by looking at the concept, and (3) rule out further studying that concept and move on to the next one. I have already managed it using several nested loops, but now I am faced with the difficulty of how to show the participant the following concept once once you have chosen the third option, that of discarding. I understand that I must include a small piece of code where a variable is created that allows me to increment it in each iteration of the loop, and that this variable should then be used to select the row of the conditions file that I use to present the stimuli (concepts and definitions ). I have tried it in the following way:

(1) in the code interface I have created a variable (it is called num\_concept) at the “beginning of the experiment”, and I have given it the value of zero.

(2) I have increased this value by one in the “end of routine” part, with the following statement: concept\_num+1.

(3) I have used this variable to select the row within the conditions file using “$num\_concept”.

When I run the layout it gives me the following error:

File “/Users/mariadolores/Dropbox/doctorado UJA/psychopy/primer articulo/primer experimento/fase\_aprendizaje/pruebas/contador\_lastrun.py”, line 114, in

trialList=data.importConditions(‘conditions\_2.csv’, selection=num\_concept),

File “/Applications/PsychoPy.app/Contents/Resources/lib/python3.8/psychopy/data/utils.py”, line 457, in importConditions

elif len(selection) \> 0:

TypeError: object of type ‘int’ has no len()

A greeting and thank you very much for the attention,  
Miguel

---

<div class="post-metadata">

**Author:** ![Chen](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/chen/32/38825_2.png) [@Chen](https://discourse.psychopy.org/u/Chen)\
**Post date:** [March 9, 2023, 6:11pm UTC](https://discourse.psychopy.org/t/select-a-specific-row-of-the-conditions-file-inside-a-loop/33741/2 "2023-03-09T18:11:51Z")

</div>

selection is not a `list`; it’s an `int`. Why are you checking its length?  
Isn’t `num_concept` just a number?

Instead of typing:

```python
elif len(selection) > 0:

```

Try:

```python
elif selection > 0:

```

---

<div class="post-metadata">

**Author:** ![miguelpostema](https://avatars.discourse-cdn.com/v4/letter/m/c0e974/32.png) [@miguelpostema](https://discourse.psychopy.org/u/miguelpostema)\
**Post date:** [March 10, 2023, 6:29am UTC](https://discourse.psychopy.org/t/select-a-specific-row-of-the-conditions-file-inside-a-loop/33741/3 "2023-03-10T06:29:58Z")

</div>

Hello Chen, thanks for the answer and for your time, however I am not very clear what you mean, my knowledge in PsychoPy is limited, so I apologize if I say something stupid. The num\_concept variable is a number, and I want to use it as a counter (which will increment progressively) to tell the loop which row of the file to select. I don’t want to know the length of that variable.

This is what I’m doing:

 ![Captura de pantalla 2023-03-10 a las 7.26.11](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/6/9/69a247f84d0bf3cd3d3c10f322c422b78c14b138.png)

![Captura de pantalla 2023-03-10 a las 7.26.32](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/3/f/3f93c74b7a046611248e9cfab1cf97a4694e2e6b.png)

 ![Captura de pantalla 2023-03-10 a las 7.26.49](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/1/c/1cfadc9b234171d906a8ddb9ca1f818934737835.png)

 ![Captura de pantalla 2023-03-10 a las 7.27.06](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/0/c/0cf0af16839dcc346a4e70c4cbfbbbb40b8922e9.png)

---

<div class="post-metadata">

**Author:** ![JensBoelte](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jensboelte/32/9060_2.png) [@JensBoelte](https://discourse.psychopy.org/u/JensBoelte)\
**Post date:** [March 10, 2023, 7:41am UTC](https://discourse.psychopy.org/t/select-a-specific-row-of-the-conditions-file-inside-a-loop/33741/4 "2023-03-10T07:41:59Z")

</div>

Hello,

I might be missing something but isn’t **num\_concepto** always 1? You increase its value by 1 when p, r or d is being pressed. So you could just write 1 into **Selected rows** or take it out of the ifelif-construction.

Best wishes Jens

---

<div class="post-metadata">

**Author:** ![miguelpostema](https://avatars.discourse-cdn.com/v4/letter/m/c0e974/32.png) [@miguelpostema](https://discourse.psychopy.org/u/miguelpostema)\
**Post date:** [March 14, 2023, 12:28pm UTC](https://discourse.psychopy.org/t/select-a-specific-row-of-the-conditions-file-inside-a-loop/33741/5 "2023-03-14T12:28:56Z")

</div>

Hello JensBoelte,  
thanks for the answer, you are right that the code is poorly written but I don’t quite understand what you mean. If I put a 1 in selected rows, won’t the first value of the variable always appear? My intention is for each of the values to appear sequentially each time the participant enters the loop. In the event that I take it out of the ifelif construction, where should I write it to achieve the goal that I have mentioned before? Thank you very much for the help

---

<div class="post-metadata">

**Author:** ![JensBoelte](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jensboelte/32/9060_2.png) [@JensBoelte](https://discourse.psychopy.org/u/JensBoelte)\
**Post date:** [March 14, 2023, 1:19pm UTC](https://discourse.psychopy.org/t/select-a-specific-row-of-the-conditions-file-inside-a-loop/33741/6 "2023-03-14T13:19:02Z")

</div>

Hello Miguel

sorry, not clear enough. You set **num\_concepto** to 0 at the beginning of the experiment and you increase it by 1 at the end of each routine. You use **num\_concepto** in **Selected rows**. AFAIK, you need to tell PsychoPy all rows that you want to select at the first iteration of the routine. I don’t think that you can iterate the row by increasing the value inserted in **Selected rows**. You might want to read this to get a better understanding of loops:

[https://www.psychopy.org/builder/flow.html#loops](https://www.psychopy.org/builder/flow.html#loops)

I add a simple toy experiment in which the concept is repeated when pressing 1 for maximally 100-times, another text is shown once when pressing 2 and another text is shown when pressing 3.

[PressedThree.psyexp](https://discourse.psychopy.org/uploads/short-url/wPCqAoBFh82DYi1Hp8uQ6emgBmk.psyexp) (18.1 KB)  
[Concept.xlsx](https://discourse.psychopy.org/uploads/short-url/lfIwWUGn2nyiS1oZOkrI9Av5s5I.xlsx) (8.4 KB)

I am not certain whether this can be adapted to your needs but I did not quite understood your experiment description.

Best wishes Jens

---

<div class="post-metadata">

**Author:** ![miguelpostema](https://avatars.discourse-cdn.com/v4/letter/m/c0e974/32.png) [@miguelpostema](https://discourse.psychopy.org/u/miguelpostema)\
**Post date:** [March 15, 2023, 6:33am UTC](https://discourse.psychopy.org/t/select-a-specific-row-of-the-conditions-file-inside-a-loop/33741/7 "2023-03-15T06:33:46Z")

</div>

Hi Jens Boelte,  
I am very thankfull for your help. I’m going to read the entry about the loops and “play” a bit with the flaw that you send me to see if I can find the solution,  
Thank you
