Getting an error on a feedback loop, when it works perfectly the block before

Hi Everyone

I have the code below which works perfectly in my practice trials

if resp_cog.corr:
    mag = "Correct! RT ={:.3f}".format(resp_cog.rt)
    magColor = "green"
    mag = "Oops! That was wrong"
    magColor = "red"
# track last 5 trials
nCorr = sum(corr[-5:])
nResps = len(corr[-5:])
mag += "({} out of {} correct)".format(nCorr, nResps)

However, in my experimental trials, the exact same code gives this error.

AttributeError: ‘int’ object has no attribute ‘append’

I don’t understand how it can work perfectly for an identical routine before, but no in this one.

Any help or suggestions would be appreciated!

This sounds like something happens between your practice trials and your experimental trials that changes corr from being a list to being a number (e.g. resetting the variable by using corr = 0, instead of corr = []). If I was you, I would open the .py file in a text editor and search for corr to see if there is anything happening to the variable that might cause this.

Also, do you coincidentally use this variable name for something else in your experimental trials?

Hey again,

Yeah I do. That is very weird, because previously I have corr = [ ] working fine across two sets of experimental trials previously but adding in the practice trials have caused an issue. I’ll change the name and see