psychopy.org | Reference | Downloads | Github

Input () EOF when reading a line

Hi everyone!
I am learning to program experiments for PsychoPy3 on a MacBook.
However, after several days trying to fix an error, I have decided to post my problem in this forum, hoping to finally be able to solve it and that maybe it can help future programmers.

I am programming a really simple task, and the problem appears when the program asks for the participant’s name.

My script is as follows (constants.py file):
NAME = input ("Insert participant name: ")

and the error is as follows:
EOFError: EOF when reading a line

I’ve already read that if you use Python 3, you should use input () instead of raw_input ().
Also it could be the version of PsychoPy 3 used (I have the most recent one)… and many other suggestions, obviously not successful for my situation.

I am so grateful for any help!

Best,
Cris

Is there actually a space between “input” and the open-parentheses? If so there shouldn’t be.

Also, you’ve made sure the error is coming from that line in particular?

Sure enough, there are no spaces (I don’t know why it appears like this here, I copied and pasted directly).
And the error is that, as it appears to me.
Insert participant name: Traceback (most recent call last):
File “mypath”, line 36, in
NAME = input(“Insert participant name:”)
EOFError: EOF when reading a line

No other clues appear, I have continued investigating but have not found any other useful information.
Thank you so much for help me!

See here: https://stackoverflow.com/questions/42891603/how-to-remove-eoferror-eof-when-reading-a-line

This is apparently just what happens with “input” when it is placed into a script. It works fine when you do it in a python console. One solution is to embed it in a try/except structure, as in that link.

Since you are using PsychoPy, another solution in general would be to use the GUI library and make this a dialog.

from psychopy import gui

Pinfo = gui.Dlg(title='Participant info')
Pinfo.addField('Insert participant name: ')
Pinfo.show()
if Pinfo.OK:
    Pdat = Pinfo.data
    NAME = Pdat[0]

A few more lines of code, but more flexible in the long run and broken into more easily identifiable parts if something needs to be fixed.

1 Like

It definitely works! :grinning:
I understand the approach, and it is true, in the console it worked initially.
I finally see my task!

Many thanks!

Best,
Cris