AttributeError: 'str' object has no attribute 'contains'

Hi everyone,

I’m reaching out for help with an issue I’m having in PsychoPy.

OS Win10
PsychoPy version 2024.2.4 Py 3.8
Standard Standalone Installation? Yes
Do you want it to also run online? Yes
What are you trying to achieve? I am setting up a 4AFC acoustic perception experiment. Choices must be selected by clicking on text according to the audio stimuli perceived.

What did you try to make it work?: I configured clickable stimuli as follows, but when I run the experiment and make a choice, it stops and get the error described in the topic.

What specifically went wrong when you tried that?:

Traceback (most recent call last):
File “C:\Users\acost\Documents\Psychopy\Prueba1_lastrun.py”, line 799, in
run(
File “C:\Users\acost\Documents\Psychopy\Prueba1_lastrun.py”, line 662, in run
if obj.contains(mouse_resp):
AttributeError: ‘str’ object has no attribute ‘contains’
2.7207 WARNING Monitor specification not found. Creating a temporary one…
ioHub Server Process Completed With Code: 0
################ Experiment ended with exit code 1 [pid:17452] #################

Thanks in advance for your time and help. I’m just starting out and would really appreciate any guidance!

Best regards.

Do you have any fields in your conditions file which have the same name as any of your stimuli? If so, those stimuli names will be overwritten by the value of those fields each trial, so when other Components try to interact with them by name (as the Keyboard Component does) it gets the value from the conditions file rather than your Component.

1 Like

Dear Todd:

Thank you very much for your reply! These are the field names of my conditions file:

Do you think the column names op1, op2, op3 and op4 might be interfering with the names of the text stimuli in the routine?

Best regards.

Hmm, they shouldn’t be - as they are different to the variable names. Could you share the psyexp file?

1 Like

Dear Todd:

Sorry for the late response, I was away. This is the psyexp file:

Prueba1.psyexp (20.9 KB)

Thank you very much for your help.

Regards.

Hi everyone,

Could someone please help me? I’m stuck and can’t make any progress with the design of my experiment. I’d really appreciate your support!

I wonder if there is some issue with _t. Try changing the text names to op1_text etc and make the same change in mouse_resp

Dear wakecarter,

Thank you very much for your reply. I did it but unfortunately I obtained the same error :frowning:

######## Running: C:\Users\acost\Documents\Psychopy\Prueba1_lastrun.py #########
Traceback (most recent call last):
File “C:\Users\acost\Documents\Psychopy\Prueba1_lastrun.py”, line 799, in
run(
File “C:\Users\acost\Documents\Psychopy\Prueba1_lastrun.py”, line 662, in run
if obj.contains(mouse_resp):
AttributeError: ‘str’ object has no attribute ‘contains’
2.9817 WARNING Monitor specification not found. Creating a temporary one…
ioHub Server Process Completed With Code: 0
################ Experiment ended with exit code 1 [pid:10368] #################

I don’t know much about builder… does it produce a python source file? It looks like confusion between the names of stimuli (maybe sound files or images) being passed as strings rather than variables. Are the op*_t stimuli Visual.Shapes of some sort? Or, are you trying to click a label that is supposed to be the ‘button’ for a sound file, but actually is the sound file ( a WAV )?

1 Like

Please could you upload your materials or add me (Wake) as a developer so I can access them and I’ll take a look?

1 Like

The screenshot shows op*_t are text components, which should work as targets for mouse clicks.

1 Like

Dear Wake,

I believe I’ve added you as a developer — I hope I did it correctly!
Thank you very much for your help, I truly appreciate it.

Regards.

What does that dialog do with hidden/escape/non-ascii/EOL characters? Does it filter them out. Are the conditions/stimuli read-in from a text file or spread sheet? I still get haunted by files that contain CRLF ( \r or ^M).

I’ve found the issue. You are using the correct answer field in your mouse component.

However, it is pointing to a column in your spreadsheet containing the text of your text components, not the text object names. It should look more like this:

audio op1 op2 op3 op4 correcta
audios/1.Y hasta pozo.wav pozo piso peso pasa op1_text
audios/2.Digo piso.wav pozo piso puso pasa op2_text
audios/1.Y hasta pozo.wav pozo peso piso pasa op1_text
audios/3.Digo peso.wav pozo peso puso pasa op2_text
audios/1.Y hasta pozo.wav pozo paso peso pisa op1_text
audios/4.Dije paso.wav pozo paso puso pisa op2_text
audios/3.Digo peso.wav peso piso paso poza op1_text
audios/8.Digo pupa.wav peso piso puso poza op2_text
audios/9.Dije pepa.wav pasa pesa poza piso op1_text
audios/6.Digo pesa.wav pasa pesa blusa piso op2_text
audios/4.Dije pasa.wav pasa pisa pesa pozo op1_text
audios/7.Dije pisa.wav pasa pisa poza peso op2_text
audios/8.Digo pupa.wav pupa pepa papa Pipo op1_text
audios/9.Dije pepa.wav pupa pepa popa papo op2_text
audios/8.Digo pupa.wav pupa papa Pepa Pipo op1_text
audios/10.Dije papa.wav pupa papa popa Pepo op2_text
audios/11.Y hasta turre.wav turre torre tarro tira op1_text
audios/12.Dije torre.wav turre torre Tere toro op2_text
audios/13.Digo fula.wav fula fila Fela fole op1_text
audios/14.Dije fila.wav fula fila falo Felo op2_text

I note that you also have at least one sound file issue

ValueError: setSound: could not find a sound file named audios/4.Dije pasa.wav

The file in the folder is called “4.Dije paso.wav”

1 Like

Dear Wake,

I’ve made the changes, but unfortunately I’m still encountering the same error :frowning:

Were you able to run the experiment in the project I shared with you?

Thank you again for your help.

Best regards,

if obj.contains(mouse_resp):

AttributeError: ‘str’ object has no attribute ‘contains’
2.8203 WARNING Monitor specification not found. Creating a temporary one…
ioHub Server Process Completed With Code: 0
################ Experiment ended with exit code 1 [pid:14596] #################

Dear Wake, dear colleagues:

I’m sorry — it turns out the problem was on my end: I had made a mistake when saving the conditions.xlsx file. Everything is working perfectly now!

I’m very grateful for your help, and I truly appreciate the support from all of you. Thank you so much for introducing me to PsychoPy!

Best regards,

1 Like