在Python中,如何在同时运行脚本的同时获取用户输入? [英] In Python, how could I get a user input while simultaneously running the script?

查看:94
本文介绍了在Python中,如何在同时运行脚本的同时获取用户输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的程序中,我试图从网站进行聊天并将其打印在控制台上。在这种情况下,我正在使用raw_input来与正在使用它的人进行聊天。我的问题是raw_input会暂停脚本的其余部分,直到我说些什么或按Enter键为止。有没有简单的方法可以解决此问题?

In my program I am trying to take the chat from a website and printing it on my console. While that's going on I'm using raw_input to get chat from whoever is using it. My problem is that raw_input pauses the rest of the script until i say something or press enter. Is there a simple way to fix this?

推荐答案

您必须使用多线程。一个线程供用户输入,另一个线程供后台任务使用。

You have to multithread. One thread for user input and another for the background tasks.

文档有点复杂(我对此很困惑),但这只是一个开始: http://docs.python.org/library/threading.html

The documentation is a bit complex (I'm pretty confused by it), but it's a start: http://docs.python.org/library/threading.html

这篇关于在Python中,如何在同时运行脚本的同时获取用户输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆