正在开发一个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
到目前为止,其在打印我exception.now希望每当这个例外时我的程序把客户ID作为输入信息。该过程应该迭代直到用户输入有效的custid。
这不是Python,所以我怀疑它运行。 – jonrsharpe
它的运行成功,为了更好地理解我编写了简单的代码.i已经在其他文件中创建了alll所需的类。 –
但您的*“简单代码”*不是有效的Python。给一个有机会跑步的[mcve]! – jonrsharpe