Python如何在不清除用户输入的情况下清除屏幕?

时间:2019-03-13 00:49:04

标签: python python-3.x

当前,我正在尝试创建一个聊天系统,但是要更新屏幕,我需要清除它,然后打印出消息。 这是我正在使用的代码,但是它也会清除运行方法clear()时用户已经输入的输入:

def receive():
    with connection.cursor() as cursor:
        while True:
        sql = "SELECT * FROM chat"
        cursor.execute(sql)
        rows = cursor.fetchall()
        for row in rows:
            print(row[0]+": "+row[1])
        time.sleep(1)
        clear()

我正在使用多处理程序,这是我尝试输入的地方:

p = multiprocessing.Process(target=receive)

p.start()

with connection.cursor() as cursor:
    while True:
        ask = input()
        if ask == "cancel()":
            p.terminate()
            clear()
            main()
        with connection.cursor() as cursor:
            sql = "insert into chat (name, message) values (%s, %s)"
            cursor.execute(sql, (name, ask))
            connection.commit()

clear被定义为clear = lambda: os.system('clear')

对于防止输入内容被删除的任何帮助,将不胜感激!

0 个答案:

没有答案