【问题标题】:Curses giving error when running curses.initscr() - python运行curses.initscr()时出现错误的诅咒-python
【发布时间】:2019-12-03 17:07:18
【问题描述】:

背景:

每当我在 IDLE 中运行 s = curses.initscr() 时,都会收到以下错误消息:

  File "C:/Users/jacob/AppData/Local/Programs/Python/Python37-32/screentest.py", line 3, in <module>
    s = curses.initscr()
  File "C:\Users\jacob\AppData\Local\Programs\Python\Python37-32\lib\curses\__init__.py", line 30, in initscr
    fd=_sys.__stdout__.fileno())
AttributeError: 'NoneType' object has no attribute 'fileno'

这是来自 PyCharm 的消息:


Redirection is not supported.

Process finished with exit code 1

当我从 DevDungeon 运行示例 sn-p 时,


print("Preparing to initialize screen...")
screen = curses.initscr()
print("Screen initialized.")
screen.refresh()

curses.napms(2000)
curses.endwin()

print("Window ended.")

在 python 启动的命令提示符下,它只是给出一个不可交互的空白屏幕。

shell 中发生的事情是否正确?

这到底是怎么回事?

我该如何解决这个问题?

请帮忙谢谢

【问题讨论】:

    标签: python-3.x windows pycharm python-idle python-curses


    【解决方案1】:

    sys.__stdout__ 是 python 进程的原始 sys.stdout。当您使用仅存在于 Windows 上的 pythonw.exe 启动 python 时,python 最初执行stdout = __stdout__ = None。 (我不确定 *nix 上会发生什么。) pythonw.exe 用于在没有关联文本控制台的情况下使用 GUI UI 运行 python。在 Windows 上,IDLE 图标和开始菜单项使用 pythonw 运行 python。与其他 GUI IDE 相同。

    curses 使用文本终端或控制台运行。它假定sys.__stdout__ 就是这样。当sys.__stdout__ 为 None 时,它​​无法工作。

    如果您从带有python -m idlelib 的命令行终端/控制台启动IDLE,sys.__stdout__ 将是那个终端,并且它会有一个fileno()。之后会发生什么我不知道。如果您的程序使用 curses,您最好在文本控制台中运行它。

    【讨论】:

      猜你喜欢
      • 2013-11-22
      • 1970-01-01
      • 2012-04-08
      • 2014-04-23
      • 1970-01-01
      • 2012-01-24
      • 2019-12-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多