下面是我写的python的一个小脚本,作用是:判断文本中的用户名在数据库中是否存在,存在返回1,不存在返回0.用的是MySQL数据库. 要注意的是:strip函数的使用,该函数的作用是去除字符串两端多余的whitespace. 所以strip的作用肯定不是像书上说的去除字符串两端多余空格. 查了一下文档说 Return a copy of the string with the leading and trailing characters removed. The chars argument…
Python编程中raise可以实现报出错误的功能,而报错的条件可以由程序员自己去定制.在面向对象编程中,可以先预留一个方法接口不实现,在其子类中实现.如果要求其子类一定要实现,不实现的时候会导致问题,那么采用raise的方式就很好.而此时产生的问题分类是NotImplementedError. 写一段代码如下: class ClassDemo: def test_demo(self): raiseNotImplementedError("my test: not implemented!&qu…