您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Python函数测试ping

Python函数测试ping

看起来您想要return关键字

def check_ping():
    hostname = "taylor"
    response = os.system("ping -c 1 " + hostname)
    # and then check the response...
    if response == 0:
        pingstatus = "Network Active"
    else:
        pingstatus = "Network Error"

    return pingstatus

您需要使用类似以下内容的变量来捕获/“接收”函数的返回值(pingstatus):

pingstatus = check_ping()

有关python函数的一些信息:

http://www.tutorialspoint.com/python/python_functions.htm

http://www.learnpython.org/en/Functions

可能需要对Python进行一个很好的入门教程,该教程将涵盖所有基础知识。我建议调查Udacity.comcodeacademy.com

python 2022/1/1 18:42:19 有521人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶