pythonneovimtry-excepteoferror

EOFError on Try, Except, Else from already working code


Doing a passwordmanager project and kept getting EOFErrors i did not understand, and chalked it up to my inexperience. Then when following the CS50P course, i also got an EOFError on code i can clearly see working for David (The tutor)

I am using Python 3.10.5 on NVIM, executing my code by using :w !python

If needed i can share my init.vim file as well, but i am on very few plugins so doubt it has anything to do with it. Expected result would be for user to input 'x' and the program returning the value or the errorcode from line 4

8 while True:
7     try:
6         x = int(input('What is x? '))
5     except ValueError:
4         print('x is not an integer ')
3     else:
2         break
1
9   print(f'x is {x}')

Solution

  • As @jasonharper said, input() can't get any input which creates your error. You have the following alternatives:

    1. You can use the following command (which I just found by looking into :h terminal): :vsplit term://python % this will create a new window on the right and executes your script.
    2. I'm using asyncrun with the following command: :AsyncRun -mode=term -pos=right -save=2 python3 %