【发布时间】:2021-01-31 11:28:25
【问题描述】:
我正在尝试编写一个 Python 程序,它使用 curses 从标准输入显示/编辑文本。 我云实现了编辑模块,但我无法将标准输入作为输入。
我该如何解决这个问题?
import curses
def main(stdscr):
while key := stdscr.getkey():
stdscr.addstr(0, 0, key)
if __name__ == '__main__':
curses.wrapper(main)
echo "hello" | python edit.py
Traceback (most recent call last):
File "/path/to/edit.py", line 8, in <module>
curses.wrapper(main)
File "/path/to/.pyenv/versions/3.9.1/lib/python3.9/curses/__init__.py", line 94, in wrapper
return func(stdscr, *args, **kwds)
File "/path/to/edit.py", line 4, in main
while key := stdscr.getkey():
_curses.error: no input
并且python edit.py(没有回显“hello”)成功完成。
【问题讨论】: