0

Python で IRC ボットを作成していますが、コンソール コマンドが必要です。

main 関数が while ループに入っているため、 を入れることができませんinput_raw()。ループを中断せずにユーザー入力を取得する方法を知っている人はいますか?

ありがとう!

4

2 に答える 2

0

質問が解決され、スレッドが使用されました、ソース:FaceBotソース

于 2012-12-15T12:38:48.740 に答える
0

でノンブロッキング ソケットの使用を試すことができますselect。何かのようなもの:

from sys import stdin
from select import select

while True:
    print "Enter command> ",
    # Add on_write sockets as necessary
    on_read, _, _ = select([stdin], [], [], 5)
    if on_read:
        command = stdin.readline()
        print "Now I can process you command..."
    else:
        print "No command, we can do here something else..."
于 2012-08-30T18:59:59.433 に答える