python-3.x - 运行curses.initscr()时出现错误的诅咒-python
问题描述
背景:
- 我最近安装了诅咒
pip install curses
- 我在网上找到了几个教程(https://www.devdungeon.com/content/curses-programming-python,https://docs.python.org/3/howto/curses.html,https://www.youtube .com/watch?v=rbasThWVb-c )
- 当我安装新包或学习新东西时,我总是不断地测试我的代码
每当我s = curses.initscr()
在 IDLE 中运行时,都会收到以下错误消息:
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 运行一个示例片段时,
print("Preparing to initialize screen...")
screen = curses.initscr()
print("Screen initialized.")
screen.refresh()
curses.napms(2000)
curses.endwin()
print("Window ended.")
在启动 python 的命令提示符下,它只是给出了一个不可交互的空白屏幕。
shell中发生的事情是否正确?
这到底是怎么回事?
我怎样才能解决这个问题?
请帮忙谢谢
解决方案
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时它不能工作。
如果你从命令行终端/控制台启动 IDLE python -m idlelib
, sys.__stdout__
将是那个终端,它会有一个 fileno()。之后会发生什么我不知道。如果您的程序使用 curses,您最好在文本控制台中运行它。
推荐阅读
- javascript - 我不知道如何在给定的领域转动轮子
- ffmpeg - 如何通过 ffmpeg (C++) 获取 rtsp-sesson 的开始时间?start_time_realtime 始终等于 -9223372036854775808
- android - 如何将 LiveData 转换为 2 个 liveData?
- excel - 如何在 CATIA 上方获取 Excel-Userform 到前台
- css - 删除具有重复类名的 div
- bootstrap-modal - Wysihtml5 破坏模态
- angular - 在 require.context() 中使用模块路径时在 afterAll [object ErrorEvent] 中引发错误
- java - 如何只在字符串中保留不同类型的字母,例如:拉丁字母、片假名、西里尔字母
- c# - 如何避免实体框架与空/空数据库的连接
- javascript - 线程以代码 0 结束 - FileSystemWatcher?