psychopy.org | Reference | Downloads | Github

Feeding a data dictionary or a list of conditions into the "Conditions" field of a loop

I was wondering if it is possible to feed conditions from a list or a data dictionary into Psychopy’s “Conditions” tab.

I have seen a similar thing done on this forum- someone put in a “$control_blocks.pop()” command into the "Conditions field, instead of xls files. However, the “control_blocks” still referenced excel files.

Is it possible to avoid excel all together in the builder?

I attempted this, by putting in the following code into the “Begin Routine” tab:

Squares = {"Square":"Squares/Square_166_light coral.jpg",
"Squares/Square_167_light coral.jpg"}

However, when I put “$Squares” into conditions, it does not recognize it.

I would love to see a successful example of not using excel for conditions and build a list or a data dictionary within the builder.

Hi @arkadiy,

Yes, you can do this using a nested loop structure, although its not ideal e.g., you have to randomize the order of stimuli yourself. In this example, in the outer loop, I have created a list of dicts (called "conds"), that is, two dicts representing two conditions and each containing a list of words. In the outer loop, at the beginning of the routine, you pop one of the dictionaries from the list of dictionaries, and pass it to a variable ("newDict"). This variable is then used in the inner loop to present the stimuli. As there are no conditions file passed to the inner loop, normally controlling the number of stimuli repetitions, you control the number of repetitions of the inner loop ("trials") using nReps. So, in the inner loop, stimuli are indexed from the variable "newDict" using the current nRep index at the start of each inner loop routine.

Example:

fileControl.psyexp (8.6 KB)

1 Like

Thank you for this solution! It works like Swiss clockwork.

I wanted to add a way to randomize everything, in case it helps future researchers. Insert the following into the code (replacing the conditions in this example):

import random

# Create the lists
list1 = ['pos1', 'pos2']
list2 = ['neg1', 'neg2']

# Shuffle each list
random.shuffle(list1)
random.shuffle(list2)

# Pass lists to two dictionaries
condition1 = {'word': list1}
condition2 = {'word': list2}

# Create a list of dictionaries
conds = []
conds.append(condition1)
conds.append(condition2)

# Shuffle The list of dictionaries
random.shuffle(conds)