What is the correct way to read sys.stdin in iPython qtconsole

社会主义新天地 提交于 2019-12-12 15:14:12

问题


I'm trying to write a library that will work as well across platforms as standard Python, iPython and within qtConsole.

Everything works except my keyboard interaction.

I want things like 'press any key' or 'press Y/N/Esc'

In Windows this is easy with msvcrt and kbhit. (though I've not tried qtconsole in windows) In Linux this works using stdin and termios under both Python and iPython.

The trouble is it seems qtconsole uses non-blocking stdin and does not support termios.

You would think this would be a good thing, simply flush stdin then check it for a character. The problem is this seems not to work. It never returns a character. It is as though ipython itself is getting in the way of stdin being fed by the terminal.

What is the correct way to read sys.stdin in qtconsole?

(BTW, there is no tag for qtconsole, this question is about qtconsole, not just iPython)

来源:https://stackoverflow.com/questions/13396653/what-is-the-correct-way-to-read-sys-stdin-in-ipython-qtconsole

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!