我试过了 win.inch(y,x) 和 win.instr(y,x) 即使 win.getch() 和 win.getkey() 没有人能达到侦探的效果?我在stackoverflow和谷歌上搜索过,但到目前为止,我没有找到解决方案。我已经读过python的诅咒手册。但仍然无法解决这个问题。
win.inch(y,x)
win.instr(y,x)
win.getch()
win.getkey()
我的代码:
import curses stdscr = curses.initscr() stdscr.addstr(1,1,'x') if stdscr.inch(1,1) == 'x': stdscr.addstr(2,1,'success') stdscr.refresh() stdscr.getch() curses.endwin()
我运行了这段代码,但屏幕上没有显示“成功”。昨晚我调试了4个小时的代码。我确信我被这个价值法官的说法所困扰 stdscr.inch(1,1,) == 'x' :“.我如何实现我的目的,看看坐标处是否有一个特定的字符串,然后执行相应的操作?
stdscr.inch(1,1,) == 'x'
curses.window.inch 返回一个 int ,不是 str .
curses.window.inch
int
str
以下行:
if stdscr.inch(1, 1) == 'x':
应该是:
if stdscr.inch(1, 1) & 0xff == ord('x'):
或使用 instr (不指定长度, 仪表,仪表 返回从给定位置开始到行尾的字符串):
instr
仪表,仪表
if stdscr.instr(1, 1, 1) == 'x':