Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在小延迟后返回两个字符串?_Python - Fatal编程技术网

Python 在小延迟后返回两个字符串?

Python 在小延迟后返回两个字符串?,python,Python,这是我的密码。我想返回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 yo

这是我的密码。我想返回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))

延迟打印的最简单方法

import time

print("first thing")
time.sleep(20)
print("second thing")
你可以让步

def gen():
    yield str1
    time.sleep(sec)
    yield str2

可能的用法之一是

for str in gen(str_list, 20):
      do_some_stuff()

请把你的代码放在代码块里。Always.use按钮
{}
格式化代码为什么需要它返回两次?返回后会发生什么?它会发送一条消息。如果我使用打印,它只在控制台上打印,它不发送消息:它的信使BoT可能考虑修改这个问题与实际代码,使用任何信使BOT API,你可能正在使用。打印不会工作,因为它打印在终端,它不发送一个消息,它需要返回我将如何实现它? 我忙了一整天,我越来越困惑:简化什么?你写的代码,我从来没有用过。我现在真的很困惑,使用收益率的函数叫做生成器,这里有一个很好的解释。如果您不关心生成器是如何工作的,并且更喜欢将其称为magic,请将其视为在每次迭代时返回值的返回语句(因此每次调用下一个(my_gen))
for str in gen(str_list, 20):
      do_some_stuff()