这是我的代码。我想返回str1并在20-30秒后返回str2。 我知道我不能两次返回str1并在str2下面。 我怎么能设置计时器,所以它返回,我试过这样,但没有任何想法。
import os
import sys
import time
from weather import *
greeting=(["Change", "change", "CHANGE"]) question_1=(["stop",
"STOP"])
str1 = """Hey [First Name]!
Are your ready for a free overview of my favorite ways to find new
income opportunities?
This is going to CHANGE the way you look at your options!
It’s kinda weird, but Facebook requires that I confirm you really want
it…so please reply and type CHANGE"""
str2 = """ Hey [First Name]! Thanks for subscribing! As promised here
is your requested link https://thebusinessofnursing.com/earn-more-now
P.S. If you ever want to unsubscribe, just type “stop”."""
def classify(msg):
msg=msg.strip()
if(msg in greeting):
return str1
def classify2(msg):
time.sleep(5)
return str2
if __name__ == '__main__':
while(1):
msg=raw_input("Write Something: ")
print(classify(msg), classify2(msg))
答案 0 :(得分:4)
你可以屈服于它
def gen():
yield str1
time.sleep(sec)
yield str2
或
def gen(str_list, delay):
yield str_list[0]
for str in str_list[1:]:
time.sleep(delay)
yield str
其中一种可能的用法可能是
for str in gen(str_list, 20):
do_some_stuff()
答案 1 :(得分:1)
延迟打印的最简单方法
import time
print("first thing")
time.sleep(20)
print("second thing")