Python中的线程+ raw_input [英] Threading + raw_input in Python
问题描述
我有一个Python脚本,它在一个子线程中执行许多操作,我希望主线程吐出raw_input("> ")
(由主线程处理),并保持输入不变在控制台底部,而子线程在上面打印内容.我最初以为我可以在子线程中使用print "\b\b" + message + "\n> "
之类的东西,但这并不能解决用户键入的字符之类的问题.因此,控制台看起来像这样:
I've got a Python script that does a bunch of things in a single subthread, and I'd like the main thread to spit out raw_input("> ")
(to be handled by the main thread), and keep that input on the bottom of the console, while the subthread prints things above. I originally thought I could use something like print "\b\b" + message + "\n> "
in the subbthread, but that doesn't account for things like characters the user has typed in. So, the console would look something like this:
[22:04] Started
[22:06] Some output
[22:06] Some more output
>
这可能吗?
推荐答案
除了 curses 建议,您可能想看看 urwid 级别的,对Python更友好的库,用于处理控制台输出.
In addition to the curses suggestions, you might want to take a look at urwid, a higher-level, more python friendly library for dealing with console output.
这篇关于Python中的线程+ raw_input的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!