Python while循环回代码中的特定点

Python while循环回代码中的特定点,python,Python,我对python非常陌生。当某个条件不满足时,我需要返回到代码中的特定点 代码如下: # Get user input on VLANs and interfaces to change print ("what VLAN ID do you want to add? "), vlan = raw_input() print ("what interface do you want to add the VLAN to? (e.g. eth10)"), interface = raw_inpu

我对python非常陌生。当某个条件不满足时,我需要返回到代码中的特定点

代码如下:

# Get user input on VLANs and interfaces to change
print ("what VLAN ID do you want to add? "),
vlan = raw_input()

print ("what interface do you want to add the VLAN to? (e.g. eth10)"),
interface = raw_input()

# Confirm details
print "So we are adding VLAN %r to interface %r" % (vlan, interface)

print ("Are the details above correct? (Yes/No)")
goodtogo = raw_input("> ")

if goodtogo == "yes":
    print "Configuring now...."

else:
    print "Please fix your error"

while goodtogo != "yes":
    print ("Starting again...")
    # Some type of code to loop back to start goes here!!

# Runs commands to add gathered config to switch
switch.runCmds(1, ["enable", "configure terminal", "vlan " + vlan, "interface " +     interface, "switchport mode access", "switchport access vlan " + vlan, "end" ])

print ("Change completed")
所以我需要做的是,当‘goodogo’不等于yes时,循环回到代码的开头。真的不知道在这里做什么

def get_vlan_iface():
    while True:
        vlan = raw_input ("what VLAN ID do you want to add? "),
        iface = raw_input("what interface do you want to add the VLAN to? (e.g. eth10)")
        print "So we are adding VLAN %r to interface %r" % (vlan, interface)

        if raw_input("Are the details above correct? (Yes/No)>")[0].lower() == "y":
             return vlan,iface
        print "Please Fix Your Entries!"

vlan,iface = get_vlan_iface()

这是一种方法

这种行为通常被称为封装和函数调用tanks,它工作得很好,但是我现在运行脚本时出现了一个错误:Traceback(最近一次调用最后一次):switch.runCmds(1,“enable”)中第38行的文件“autovlan2.py”,“配置终端”,“vlan”+vlan,“接口”+iface,“交换机端口模式访问”,“交换机端口访问vlan”+vlan,“结束”)TypeError:无法连接'str'和'tuple'对象。它指的是我切换的最后一行代码。runCmdsAh,是的,在vlan=raw_输入行的末尾有一个胭脂。打印vlan时,它显示为('1111',),我删除了,现在可以处理了。再次感谢