简体   繁体   English

当表名已经存在时,我想显示一条消息,但还要再次询问一个新的表名

[英]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"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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