zoukankan      html  css  js  c++  java
  • 10.3.3 带有多个except的try语句:

    同样,首先尝试执行try子句,如果没有错误,忽略所有的except从句继续执行。
    
    如果发生异常,解释器将在这一串处理器(except)子句中查找匹配的异常。
    
    
    如果找到对应的处理器,执行流将跳转到这里。
    
    def safe_float(obj):
      try:
        retval = float(obj)
      except ValueError:
         retval = 'could not convert non-number to float'
      except TypeError:
         retval = 'object type cannot be converted to float'
      return retval
    a=safe_float('aaa')
    print a
    
    
    C:Python27python.exe C:/Users/TLCB/PycharmProjects/untitled/mycompany/ddd/a16.py
    could not convert non-number to float
    
    
    def safe_float(obj):
      try:
        retval = float(obj)
      except ValueError:
         retval = 'could not convert non-number to float'
      except TypeError:
         retval = 'object type cannot be converted to float'
      return retval
    class  test(object):
          def __init__(self):
              pass
    b=test()
    print type(b)
    a=safe_float(b)
    print a
    
    C:Python27python.exe C:/Users/TLCB/PycharmProjects/untitled/mycompany/ddd/a16.py
    <class '__main__.test'>
    object type cannot be converted to float
    

  • 相关阅读:
    上架的问题
    moya rxswift的简单实用
    MySql的简单使用,所有的代码基于MAC
    H5测试区别与PC端测试关注点
    测试小结
    测试之找回密码
    转Web安全测试之XSS
    一个最简单的登录页面测试case
    web测试特别点
    关于web测试
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349238.html
Copyright © 2011-2022 走看看