37,719
社区成员
发帖
与我相关
我的任务
分享
while right!=1:
os.system('pause')
pswd1=raw_input("please enter password:")
不过最后又出现了,请按任意键继续. . .。这个是不是又要用到输出重定向呀right=0
while right!=1:
pswd1=raw_input("please enter password:")
pswd=self.getPasswd()
if pswd1==pswd:
right=1
self.setWrongTimes(0)
else:
self.setWrongTime(time.time()) #record the time when wrong input occur
self.wrongTimes+=1
print "password wrong!"
self.setWrongTimes(self.wrongTimes) # set wrongs times
self.WiatTime() # wiat
def WiatTime(self): #according the password input wrong times set a wait time,at this time you can't enter password
times=self.getWrongTimes() #wrong times
wrongTime =self.getWrongTime() #the time last wrong input accour
if times <= 3:
pass
if times >3:
currentTime=long(time.time())
waitTime=currentTime-wrongTime
if waitTime>times*times:
pass
else:
timeYouShouldWait=times*times-(currentTime-wrongTime)
print "you should wait for some sec: ",
for i in range(timeYouShouldWait):
time.sleep(1)
theTimeLave=timeYouShouldWait-i
if theTimeLave<10:
print "\b\b\b",str(theTimeLave),
elif theTimeLave<100:
print "\b\b\b\b",str(theTimeLave),
elif theTimeLave<1000:
print "\b\b\b\b\b\b",str(theTimeLave),
print
11楼的方法是可以的。下楼上试验结果。
#include <unistd.h>
#include <stdio.h>
#include <termios.h>
void main(void)
{
char c;
sleep(5);
printf("wake up\n");
tcflush(0,TCIFLUSH);
while((c=getchar())!='\n'&&c!=EOF)putchar(c);
return;
}
so, the similar codes in python is in the url panghuhu250 offered.
import time
import subprocess
import sys
from termios import tcflush, TCIOFLUSH
alarm1 = int(raw_input("How many minutes (alarm1)? "))
while (1):
time.sleep(60*alarm1)
print "Alarm1"
sys.stdout.flush();
tcflush(sys.stdin, TCIOFLUSH)
doit = raw_input("Continue (Y/N)?[Y]: ")
print "Input",doit
if doit == 'N' or doit=='n':
print "Exiting....."
break
Again, I apologize for all the confusion I brought over here and will pay more attention on my post...
import os
oldf=sys.stdin
f=open(os.devnull, 'r')
sys.stdin=f