1. input() 输入多个数字
while True:
user_choice=input("请输入(help:帮助):")
if user_choice=="SAT":
t_hour,t_min,t_sec=eval(input("请输入(以,分隔):"))
print("输入的结果是:",t_hour,t_min,t_sec)
elif user_choice=="q" or user_choice=="Q": #如果输入q、Q
break
2.定时每天自动执行线程任务
#!/usr/bin/python
from threading import Timer
import time
import threading
import sys
# 定义线程调用函数
class threading_TWHA(threading.Thread):
def __init__(self, threadID, name, counter):
threading.Thread.__init__(self)
self.threadID = threadID
self.name = name
self.counter = counter
def run(self):
while True:
time_now = time.strftime("%H:%M:%S", time.localtime()) # 刷新
if time_now == t_now1:
print("Server打开")
print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
time.sleep(2) # 因为以秒定时,所以暂停2秒,使之不会在1秒内执行多次
if time_now == t_now0:
print("Server关闭")
print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
time.sleep(2) # 因为以秒定时,所以暂停2秒,使之不会在1秒内执行多次
if user_choice=="SA0" or user_choice=="sa0": # 关闭自动开关机线程
print("Server线程关闭")
return
t_now1 = "17:22:00" # 自动开机时间初始化
t_now0 = "17:22:10" # 自动关机时间初始化
while True:
user_choice=input("请输入(help:帮助):")
if user_choice=="SA1" or user_choice=="sa1": # 开始自动开关机线程
thread3 = threading_TWHA(3,"heWaterHeaterAuto",3)
thread3.start()
print("Server线程打开")
if user_choice=="SAT1" or user_choice=="sat1": # 开机时间设置
t_now1=input("Server自动开机时间修改(例如:15:30:00):")
print("输入结果是:",t_now1)
if user_choice=="SAT0" or user_choice=="sat0": # 关机时间设置
t_now0=input("Server自动开机时间修改(例如:15:30:00):")
print("输入结果是:",t_now0)
if user_choice=="q" or user_choice=="Q": #如果输入q、Q
user_choice="sa0" # 先退出线程
break