传递函数将值返回给另一个函数

时间:2019-08-25 09:48:45

标签: python-3.x function

我创建了一个函数,该函数从设备检索信息,然后将凭据放入字典中。然后将其作为字典值返回。

当我使用此信息运行另一个功能时,它可以工作,但似乎又运行了另一个功能,因为我从第一个功能中获得了相同的输出。

它的任务之一是连接,然后告诉您有多少设备。第一次这么做

与10.1.42.23的连接正在工作 总共测试并连接了1个路由器 你想继续吗? y

但是当它使用返回的字典移至下一个功能时,它会再次说并添加1,就像重新运行其他功能一样

如果您只是为了打印返回的字典而执行测试功能,它将正确打印它并且该功能可以正常工作,但是它会先重新运行其他功能-我认为!

我尝试查看导致问题的函数是否再次在代码中重新运行,但没有重新运行

附加评论-谢谢大家的评论,下面的内容应该足以让您了解我要做什么

def main():

    device_connection_test_to_switches()

    ! calls a function to display a menu and asks for you to make a choice
    choice = input("Select an Option: ")
    if choice == "1":
        choice1_input = input("Are you sure you want to run the full audit? ")
        choice1_input = choice1_input.lower()
        if choice1_input == "y" or choice1_input == "yes":
            full_audit()
        else:
            print("Not a valid option try again!")

def full_audit():

    create_running_configs_switches(device_connection_test_to_switches())



def device_connection_test_to_switches():
    ! 50 lines of code that results in creating a dictionary
    return switch_dict
    wb.save("Network_Audit.xlsx")

def create_running_configs_switches(switch_dict):
    cv = 1
    for k, v in switch_dict.items():
        connection = ConnectHandler(**v)
        run_conf_out = connection.send_command("show run")
        connection.disconnect()

0 个答案:

没有答案