psychopy.org | Reference | Downloads | Github

Attribute error: 'str' object has no attribute 'tStart'

Peace be upon you.
I’m using psychopy standalone version 3.2 on Win 10.
My experiment involves a stroop task followed by a task that requires subjects to enter text responses. I have used the following code


And also added screen_text = ’ ’ in the ‘begin routine’ part of the code.
The experiment ran fine before I added a stroop task in the beginning.
On running the experiment it crashes after the stroop task at the start of the routine requiring text responses.
This is the error message that it gives:

File “C:\Users\Admin\Documents\PsychoPy3 Demos\CCA\CRA_lastrun.py”, line 673, in
thisComponent.tStart = None
AttributeError: ‘str’ object has no attribute ‘tStart’
I have absolutely no background in programming.
I came across a similar question


However I don’t know whether it applies to my scenario, and even if it does, how to proceed with it.

Salaam alaykum,

Is screen_text the name of your text component? If so, in the code above, you just overwrote it with the typed characters. i.e. a text component is a complex object, with lots of attributes, like a start time, a font, a position, and so on. You can’t replace it just with a “string” object, which is just a character like the letter 'a' for example, because a set of letters doesn’t have any of those other attributes.

So I think in this case, what you want to do is just update the relevant attribute of your text component, like this:

screen_text.text = ''.join(key_resp.keys)

i.e. don’t replace the entire component with the response values, but just its .text attribute.

No, screen_text is not the name of the text component. Here’s what it looks like:


The experiment works fine on its own, however when I add the stroop task behind it, it crashes as soon as the routine starts.
The routine contains two text components, a keyboard response component and the code component I mentioned previously.

OK, I think I got waylaid by your initial post: there is no necessary link between the error and the variable screen_text. So we need to determine what component is causing the error. You should compile the script (by pushing the “compile to script” button on the tool bar), and then edit the result in the Coder window.

Immediately before line 673 (thisComponent.tStart = None), please put:

print('Component: ', thisComponent.name)

NB make sure this new line of code has the exact same amount of indentation spaces as the next one (i.e. thisComponent.tStart = None).

Save the file, and then run the script from within the Coder Window (by just pushing the green “run” icon there).

Notice in the output window what name is the last to be printed before the error occurs.

Turns out this invisible component doesn’t have any name either. :laughing:

 File "C:\Users\Admin\Documents\PsychoPy3 Demos\CCA\CRA.py", line 674, in <module>
    print('Component:', thisComponent.name)
AttributeError: 'str' object has no attribute 'name'

OK, but whatever component it is, somewhere along the line it has been overwritten with a simple string value.

My guess is that somewhere in your code, you have a line that starts like this:

name_of_some_component = 'something'

In each .py script, a stimulus component will generally just be defined once, looking like this:

text_2 = visual.TextStim(win, blah blah)

The attributes of that component might get updated, like this:

text_2.pos = [new_x, new_y]

but you should never see another line that just starts with:

text_2 = blah blah

I’m not saying that text_2 is the culprit here, but you should look through your code for any re-assignments of things that have the same name as any of your components.

PS on second thoughts, the debugging code above should give you some hints: it should be printing out names of the components that aren’t affected until it hits the one with the error, so you can rule out those ones from consideration. There will be some others that don’t get printed out just because the error occurs before the code gets to them, though.

1 Like