看起来您想要
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()
注意:ping -c
适用于Linux,适用于Windowsping -n
有关python函数的一些信息:
http://www.tutorialspoint.com/python/python_functions.htm
http://www.learnpython.org/en/Functions
可能需要对Python进行一个很好的入门教程,该教程将涵盖所有基础知识。我建议调查Udacity.com和preacademy.com