【发布时间】:2015-11-04 00:57:23
【问题描述】:
正在开发一个 python 应用程序。我已经从数据库中验证了客户 ID。表示如果输入的 custid 存在于数据库中,我将引发异常。在异常类中,我正在打印消息。到目前为止,它正在打印消息。但我不知道如何让控制权回到我接受输入的语句。 主应用
Custid=input("enter custid)
Validate_custid(Custid)
Print(Custid)
validate_custid 模块
From connections import cursor
From customExceptions import invalidcustidException
Def validate_custid(custid):
Cursor.execute("select count(custid) from customer where custid=:custid",{"custid":custid})
For row in cursor:
Count=row[0]
If Count==0:
Raise invalidcustidException
到目前为止,它在异常中打印消息。现在我希望我的程序在发生此异常时将 custid 作为输入。该过程应该迭代,直到用户输入有效的 custid。
【问题讨论】:
-
那不是 Python,所以我怀疑它可以运行。
-
它运行成功,为了更好地理解,我编写了简单的代码。我在其他文件中创建了所有需要的类。
-
但是您的 "simple code" 不是有效的 Python。给一个有机会跑的minimal reproducible example!
-
看起来他只是将每一行的第一个字母大写。
-
是的..对不起,我正在通过我的手机输入,所以忘记输入小写。模块很好。它的工作。我只是无法获得控制权。
标签: python database python-3.x custom-exceptions