Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
302 views
in Technique[技术] by (71.8m points)

Python 3: EOF when reading a line (Sublime Text 2 is angry)

while True:
    reply = input('Enter text')
    if reply == 'stop': break
    print(reply.upper())

The result was:

Enter text:Traceback (most recent call last):
  File "C:PythonProjects5.py", line 2, in <module>
    reply = input('Enter text:')
EOFError: EOF when reading a line
[Finished in 0.2s with exit code 1]

It is only in Sublime Text 2. I tried IDLE, tried command line, everything is perfect. Why should Subleme shout at me?

By the way, maybe you could also explain my what EOF may mean in such situation. Of course, I have read in the documentation, that if EOF is read from input, the appropriate error is raised. I would like to model this situation. Is input only about the keyboard? If yes, what combination of keys should I input to get EOF?

Thank you in advance.

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I had the same problem. The problem with the Sublime Text's default console is that it does not support input.

To solve it, you have to install a package called SublimeREPL. SublimeREPL provides a Python interpreter which accepts input.

There is an article that explains the solution in detail.

GitHub page for SublimeREPL


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...