欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程语言 > python >内容正文

python

python刷新_如何在python中刷新输入流?

发布时间:2024/9/27 python 37 豆豆
生活随笔 收集整理的这篇文章主要介绍了 python刷新_如何在python中刷新输入流? 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

这将有助于了解您正在使用的操作系统,因为这是一个非常特定于操作系统的问题。例如,Kylar的答案在Windows上不起作用,因为sys.stdin没有fileno属性。

我很好奇,用咒语拼凑出一个解决方案,但这在Windows上也行不通:#!/usr/bin/python

import time

import sys

import curses

def alarmloop(stdscr):

stdscr.addstr("How many seconds (alarm1)? ")

curses.echo()

alarm1 = int(stdscr.getstr())

while (1):

time.sleep(alarm1)

curses.flushinp()

stdscr.clear()

stdscr.addstr("Alarm1\n")

stdscr.addstr("Continue (Y/N)?[Y]:")

doit = stdscr.getch()

stdscr.addstr("\n")

stdscr.addstr("Input "+chr(doit)+"\n")

stdscr.refresh()

if doit == ord('N') or doit == ord('n'):

stdscr.addstr("Exiting.....\n")

break

curses.wrapper(alarmloop)

编辑:啊,Windows。然后可以使用msvcrt模块。请注意,下面的代码并不完美,它在空闲状态下根本不工作:#!/usr/bin/python

import time

import subprocess

import sys

import msvcrt

alarm1 = int(raw_input("How many seconds (alarm1)? "))

while (1):

time.sleep(alarm1)

print "Alarm1"

sys.stdout.flush()

# Try to flush the buffer

while msvcrt.kbhit():

msvcrt.getch()

print "Continue (Y/N)?[Y]"

doit = msvcrt.getch()

print "Input",doit

if doit == 'N' or doit=='n':

print "Exiting....."

break

总结

以上是生活随笔为你收集整理的python刷新_如何在python中刷新输入流?的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。