简体   繁体   English

之前的function在python完成后如何调用函数?

[英]How to call functions after previous function is completed in python?

When function1 is successfully finished then run function2.当 function1 成功完成后,运行 function2。 But this need to be in function2, not as if statement outside of functions.但这需要在 function2 中,而不是函数外的 if 语句。 How to call success finish of function1?如何调用 function1 的成功完成?

EDIT编辑

import time

def function1():
    print ('This is function1!')
    time.sleep(5)
    print ('Function1 is successful')

function1()

def function2():
    if function1 is success #this part I don't get (How to write this line?)
        print ('This is something about function1')
    else:
        pass
function2()

Use a global variable.使用全局变量。 Set it in function1, and check it in function2.在function1中设置,在function2中检查。

function1_success = False

def function1():
    global function1_success
    # do stuff ...
    if success:
        function1_success = True

def function2():
    global function1_success
    if function1_success:
        # do stuff ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 python中celery组任务全部完成后如何调用方法 - How to call the method after all the celery group tasks are completed in python 如何在Python中调用列表中的下一个/上一个对象的函数 - How to call functions of next/previous object in list in Python 在 Python 中完成前一个函数后,在 cmd 中调用第二个函数 - Call a second function in cmd after the previous one finished in Python 如何在python中调用函数列表中的函数 - How to call a function in a list of functions in python Python - 如何在调用另一个函数后返回上一个函数? - Python - How to return to previous function after calling another function? 如何拥有一个通用的函数调用,可以在Python中调用不同的函数? - How to have a versatile function call that can call different functions in Python? 完成后,如何让ttk.progressbar调用函数(Python)? - How can I have a ttk.progressbar call a function when it is completed (Python)? APScheduler 回调函数 - 作业完成后如何在 python 中调用某些功能/模块? - APScheduler callback function - how can I call some funtion/module in python when a job is completed? 如何在python中调用函数 - How to call functions in python 随机调用函数然后在 Python 中调用不同的函数 - Call Functions at Random then Call a Different Function in Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM