python刷新_如何在python中刷新输入流?
這將有助于了解您正在使用的操作系統(tǒng),因為這是一個非常特定于操作系統(tǒng)的問題。例如,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模塊。請注意,下面的代碼并不完美,它在空閑狀態(tài)下根本不工作:#!/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
總結(jié)
以上是生活随笔為你收集整理的python刷新_如何在python中刷新输入流?的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java生成pdf怎么合并行或者列_Ja
- 下一篇: android adb 静默安装,And