如何修复 python 3.7 中的“RuntimeError:input():lost sys.stdin”错误

mac*_*ch3 10 python file-io user-input pycharm python-3.x

我正在练习一些代码,当我运行一段非常常见的代码时,似乎突然出现了这个错误。我正在解决的问题需要输入,计算一些内容并给出输出。

我在一个在线 IDE(一些编码竞赛网站)上运行它,由于它不是很好(这并不奇怪!),我决定在 Pycharm 社区版上运行它,然后将其复制粘贴到那里。它没有给我输出,而是显示了这个,

Traceback (most recent call last):
  File "D:\Software\lib\io.py", line 52, in <module>
  File "D:\practice\abc.py", line 1, in <module>
RuntimeError: input(): lost sys.stdin

Process finished with exit code -1073740791 (0xC0000409)
Run Code Online (Sandbox Code Playgroud)

我尝试运行的代码是这样的,

tc = int(input())
while tc > 0:
    c = 0
    a = int(input())

    while a > 0:
        print(a % 2)
        if (a % 2 == 0):
            a = a // 2
            c += a
    print(c, "is c")

    tc -= 1
Run Code Online (Sandbox Code Playgroud)

这可能有帮助,也可能没有帮助,但我不知道出了什么问题。

gre*_*ego 4

该问题可能与您的代码编辑器/Python 窗口有关。例如,QGIS Python 控制台没有标准输入或标准输出,因此如果在那里运行代码,您会收到“RuntimeError:input():lost sys.stdin”错误。

请参阅这篇文章: https://gis.stackexchange.com/questions/343250/error-when-using-input-pyqgis-runtimeerror-input-lost-sys-stdin-qgis-3