0

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}')
flixeren
  • 3
  • 2
  • I don't have any experience running Python in vim, but the EOFError suggests it is expecting input to come from a file, and because no input file exists, the input() function is raising EOFError. – nigh_anxiety Jul 28 '22 at 00:23
  • What do you mean by input file? Code works perfectly when i import it into VSCode – flixeren Jul 28 '22 at 00:40
  • `:w !python` is sending your editor buffer as the input to Python. There is no provision for any other input, so your `input()` has no place to read from. I don't know what the proper way is to run an interactive script from inside NVIM, but this certainly isn't it. – jasonharper Jul 28 '22 at 00:50

1 Answers1

0

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 %
TornaxO7
  • 1,150
  • 9
  • 24