Form object not subscriptable

When attempting to use data from a Form component e.g., form[1].response, I’m just getting errors about the Form object not being subscriptable. Any suggestions how to get around this?

(I’m essentially trying to get a simple “if any of the form responses >0, do this” sorted.)


The form component has an attribute called getData() - see Forms API. This brings up not only the data but also the form’s attributes. The format of the output seems to be an ordered dictionary within a list where one list is one question of the form.

To get the response value from getData(), in a code component end of routine tab type the below where form is then mane of the form component.

for k, v in enumerate(form.getData()): # loop through each list
    for key, value in v.items(): # loop though each dictionary
        if key == 'response':
            if value > 0:
                # do something

Note, if you attempt to print the above to the stdout, rather confusingly only prints the response to the first question only but in the background all responses are saved at the end of the routine.

Hope this helps

Best wishes,

Many many thanks, Yiannis. Very helpful. I’d stumbled upon form.getData(), but didn’t know how to access its lists/properties.

And I’ve tried the code your provided, but get this error:

    if value > 0:
TypeError: '>' not supported between instances of 'NoneType' and 'int'

Any chance you can upload a minimal example of your exp?