Python代码在Mac终端中运行,但不是从Neovim运行

时间:2020-07-27 23:29:51

标签: python python-3.x vim neovim

我最近学习了Vim(NeoVim)的基础知识,并开始在Python网站上阅读有关Python 3的教程。我写了这个简单的脚本ask.py

def ask_ok(prompt, retries=4, reminder='Please try again!'):    
    while True:    
        ok = input(prompt)    
        if ok in ('y', 'ye', 'yes'):    
            return True    
        if ok in ('n', 'no', 'nop', 'nope'):    
            return False    
        retries = retries - 1    
        if retries < 0:    
            raise ValueError('invalid user response')    
        print(reminder)    
            
ask_ok("Here is a question", 3, "Give a better answer!") 

要在此测试4.7.1中定义的功能:https://docs.python.org/3/tutorial/controlflow.html#defining-functions

当我退出Neovim并运行python3 ask.pypython ask.py时,脚本将运行。但是,当我进入Neovim并运行:!python3 ask.py:!python ask.py时,出现此错误:

!python ask.py 
Here is a questionTraceback (most recent call last):
  File "ask.py", line 13, in <module>
    ask_ok("Here is a question", 3, "Give a better answer!")
  File "ask.py", line 3, in ask_ok
    ok = input(prompt)
EOFError: EOF when reading a line

shell returned 1

为什么从Neovim运行时错误返回脚本,而当我直接在终端中运行时却返回错误?

0 个答案:

没有答案