简体   繁体   English

同时使用input()和print()(例如在聊天中)

[英]Use input() and print() at the same time (like in a chat)

I am learning Python, and I have decided to make some practise by coding a mini chat in terminal, with a server and a client. 我正在学习Python,因此我决定通过在带有服务器和客户端的终端中编写小型聊天来进行一些练习。 But there is a problem, to make a real chat, the client must be able to type, send and receive messages in the same time like that: 但是有一个问题,要进行真正的聊天,客户端必须能够同时输入,发送和接收消息,如下所示:

//MESSAGES
>bla bla to send

So messages are scrolling while in the bottom of the shell, there's my input. 因此,消息在外壳底部滚动时,有我的输入。

I have searched the web how to make that, maybe the multi-threading, no. 我已经在网上搜索了如何实现这一点,也许是多线程的。 The input() fonction blocks the process. input()功能阻止该过程。

If you have an answer to my question, it'll be great! 如果您对我的问题有答案,那就太好了! Thanks in advance! 提前致谢!

On Unix systems, you might want to check out curses , which is a library designed to do this type of thing. 在Unix系统上,您可能想检查cursescurses是一个旨在执行此类操作的库。 Python has a module for it in the standard library. Python在标准库中为其提供了一个模块

There is a good tutorial on using curses in the docs . 文档中有一个关于使用curses的很好的教程。 This also suggests the console module for Windows users. 这也建议Windows用户使用控制台模块

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM