简体   繁体   中英

When table name already exist I want to show a message but also ask again for a new table name

I want to verify if a table exist, if exist I want to show a message "Table already exist" and ask again user to enter a new name for table.

But when user enter a table name that already exist, Im getting only the message "Table already exist" but its not asking again to enter the name for the table.

Do you know why its not working?

def validField(info):
    field = ""
    while not field:
        field = raw_input(info)
        if not field:
            print "Empty field"
    return field

def createTable():
    tableName = validField("Please enter the name for table: ")
    try:
        verifyTable = test.get_table(tableName)
    except BotoServerError:
        print "Table already exist" 
        tableName = validField("Please enter the name for table: ")

How about:

def createTable():
    ok = False
    while not ok:
        try:
            verifyTable = test.get_table(raw_input("Please enter the name for table: "))
            ok = True
        except BotoServerError:
            print "Table already exist"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM