| Reference | Downloads | Github

TypeError: '>=' not supported between instances of 'list' and 'float'


Hello fellows,

Working on version 3.0.5 on a Mac

I am designing a 2-back experiment and I am using a code to present correct feedback to the first block of training. I have already used code like this on previous versions of Psychopy, in fact. Something like:

if RT.keys != None and RT.rt <= 0.15 :
    feed = 'Anticipated!'
elif RT.keys = corrResp and RT.rt > 0.15 : 
    feed = 'Correct!'

RT is my RT for the stimuli and feed my updateable text to give feedback.

This is not working on version 3.0.5, besides used to work on version 1.90.3. If no button is pressed, error above shows:

TypeError: ‘>=’ not supported between instances of ‘list’ and ‘float’

Thanks for any help or ideas.


Hi @felipeviegas, there are two reasons why you are getting the error. RT.rt is an empty list until it is populated with an RT. Actually, this depends on how you are storing your information for your keyboard. If you store first or last response, RT.rt overwrites the rt list container and stores your RT as a float. If you store all responses, the RTs are stored in a list. So, RT.rt <= 0.15 fails without a response because Python will not attempt to comparisons between a float and an empty list. This failure is triggered because the first part of your conditional does not correctly asses whether a response has been made: RT.keys != None will always be True because None != []. Instead, you want to check if the list has any responses inside by checking its length:

if len(RT.keys) and RT.rt <= 0.15 :
    feed = 'Anticipated!'
elif RT.keys == corrResp and RT.rt > 0.15 : 
    feed = 'Correct!'

There is also a typo in your second conditional, where you assign corrResp to your RT.keys attribute, rather than check for equality (changed above).


Hi @dvbridgesm thank you so much for your answer. The codo:

if len(RT.keys) and RT.rt <= 0.15

also fails. Psychopy tells:

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

I imagined that some of this equality checks would tell psychopy to verify if there is any answer and then (only then) try the comparison.
My original code is more simple, I was not checking for anticipation:

if nBack.corr == 1 :
    feed = 'Correta!'
elif nBack.corr == 0 and nBack.rt > 0:
    feed = 'Errou!'
    feed = 'Não respondeu!'

So code works no problems. I will just have to figure out some way to prevent anticipation. Any thoughts still are appreciated.



Apologies, I had not realised you have inserted this code at the end of the routine (it must have been if RT.keys is None). So, actually, your original code was probably fine, depending on the keyboard settings. What responses are you saving? All keys, or something else? If you are saving all keys, rts are stored in a list, and so you have to get the value out of the list before making a comparison with a float:

if RT.keys != None and RT.rt[-1] <= 0.15:


Hi @dvbridges, I am storing last key (is this fine, right?), so every trial has one key response saved. I have actually made the code to work with:

if RT.keys != None and RT.rt <= 0.15 :
    feed = 'Antecipada!'
elif  RT.keys == None :
    feed = 'Aperte "M" ou "Z"!'
elif RT.keys == corrResp : 
    feed = 'Correta!'
elif RT.keys != corrResp: 
    feed = 'Errou!'

I believe it is another solution possible, isn’t it? This order of response check saves anticipated responses and dismiss the need to check if RT.rt is above 0.15 when response is correct or wrong. At least it seems to work and save fine on my tests. I will double check.

I have also managed to use this code at the valid trials to save the type of response (correct, wrong, anticipated or omitted), which will save me a lot of time at the data analysis. Very happy with this. Just added a code at the end of the routine:


Thanks a lot for your answers and for enlightening me about comparing an empty list with a float.



Great. Yes, there several many combinations of settings, but looks like you have it fixed :slight_smile: