1.使用list实现依次调用函数功能
def check_network():
print "This is check_network"
def check_config():
print "This is check config"
def check_io():
print "This is check io"
if __name__ == '__main__':
func_list = [check_network, check_config, check_io]
for func_name in func_list:
func_name()
output:
This is check_network
This is check config
This is check io
2.使用dict实现调用函数功能
def check_network():
print "This is check_network"
def check_config():
print "This is check config"
def check_io():
print "This is check io"
if __name__ == '__main__':
func_dict = {'check_network': check_network(), 'check_config': check_config(), 'check_io': check_io()}
for func_name in func_dict:
func_dict[func_name]
output:
This is check_network
This is check config
This is check io