1.异常基础 python在运行过程中,程序解释机制会测试代码,如检测不通过则会抛出异常. try: aa = 10 bb = ' cc = aa + bb except Exception as e: print('error:',e) #output输出异常,数字不能与字符向加 error: unsupported operand type(s) for +: 'int' and 'str' try: aa = 10 bb = '10' cc = aa + bbexcept TypeErro…
1.针对类中方法的反射 # 反射的使用 class Dog(object): def __init__(self,name): self.name = name def eat(self): print('%s is eating...'%self.name) def bulk(self): print('%s is yaling...'%self.name) d = Dog('wt') choice = input('>>:').strip() if hasattr(d,choice): f…