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

时间秒杀一切 提交于 2019-12-11 07:43:51

问题


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. 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.

If you have an answer to my question, it'll be great! Thanks in advance!


回答1:


On Unix systems, you might want to check out curses, which is a library designed to do this type of thing. Python has a module for it in the standard library.

There is a good tutorial on using curses in the docs. This also suggests the console module for Windows users.



来源:https://stackoverflow.com/questions/12010446/use-input-and-print-at-the-same-time-like-in-a-chat

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