【问题标题】:Why does the IPython error about "input" mention "raw_input"?为什么关于“输入”的 IPython 错误会提到“raw_input”?
【发布时间】:2021-12-16 19:23:10
【问题描述】:

我有以下代码行来接受标识符:

security = input("Insert ID")

这在我的 python 上效果很好。但是,当我将笔记本发送给同事时,会出现此错误:

StdinNotImplementedError                  Traceback (most recent call last)
<ipython-input-1-324a5244d6ce> in <module>
      1 ## Insert NIM/PREL or active Bond here
----> 2 security = input("Insert Bond ID or Figi # -- e.x. 025816CH0 Corp, BBG012JJ3534 ") #BQ3149326 credit ag #BQ4561651 jag #025816CH0 AMEX #BR0344159 PREL EXAMPLE #BR1139871 PREL INR

C:\axy\py\environments\quant2\lib\site-packages\ipykernel\kernelbase.py in raw_input(self, prompt)
    853         if not self._allow_stdin:
    854             raise StdinNotImplementedError(
--> 855                 "raw_input was called, but this frontend does not support input requests."
    856             )
    857         return self._input_request(str(prompt),

StdinNotImplementedError: raw_input was called, but this frontend does not support input requests.

什么可能导致这种不匹配?

【问题讨论】:

  • 我编辑了这个问题以澄清您的确切要求。如果我误解了,一定要edit 修复它。如果您这样做,LMK 可以更新我的答案。我假设您已阅读并理解错误消息,但您对细节感到困惑。

标签: python ipython


【解决方案1】:

出于历史原因,IPython 将 input 称为 raw_input

Python 2 的 raw_input 在 Python 3 中重命名为 input。有关详细信息,请参阅 What's the difference between `raw_input()` and `input()` in Python 3?

IPython 曾经支持 Python 2 和 3,所以它的代码如下:

if PY3:
    ...
    builtin_mod.input = self.raw_input
else:
    ...
    builtin_mod.raw_input = self.raw_input

然后他们在 6.0 版中放弃了对 Python 2 的支持,所以它变成了:

...
builtin_mod.input = self.raw_input

Here's the diff on GitHub

【讨论】:

    猜你喜欢
    • 2019-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-22
    • 2017-04-23
    • 1970-01-01
    相关资源
    最近更新 更多