Python Basic Learning Code errors and exceptions

Source: Internet
Author: User

DEF FUNC1 ():     try:        return float (' abc ')     except valueerror,e:        print  EDEF FUNC2 ():    try:        astr  =  ' abc '         float (ASTR)     except  Valueerror:        astr = none    return  ASTRDEF FUNC3 ():     try:        astr  =  ' abc '         float (ASTR)     except  ValueError:        astr =  ' Count not convert  non-number to float '     return astrdef safe_float (argment):     tRy:        retval = float (argment)      except valueerror:        retval =  ' Count not  convert non-number to float '     except TypeError:         retval =  ' Object type cannot be convert  to float '     return  retvaldef func4 (argment):     try:        retval = float (argment)      except  (valueerror,typeerror):        retval =  ' Argment must be a number or numeric string '     return   retvaldef func5 (argment):    try:         retval = flOat (argment)     except ValueError,e:         Print e    print type (e)     print e.__class__     print e.__class__.__doc__    print e.__class__.__name__def  func6 (argment):     try:        retval =  float (argment)     except  (valueerror,typeerror),e:         retval = str (e)     return  retvaldef main ():     ' handles all the data processing '     log  = open (' E:\\cardlog.txt ', ' W ')     try:         ccfile = open (' E:\\cardlog.txt ', ' R ')         txns  = ccfile.readlines () &NBsp;   except ioerror,e:        log.write (' No  txns this month\n ')         log.close ()          return    ccfile.close ()     total  = 0.00    log.write (' account log:\n ')     for  Eachtxn in txns:        result = func6 (EACHTXN)         if isinstance (result,float):             total += result             log.write (' data...processed\n ')          else:            log.write (' ignored:%s '% Result)     PRINT  ' $%.2f newbalance '  % total    log.close () #if  __name__ ==  ' __ Main__ ': #    main () Def func7 ():    assert 1 ==  0def func8 ():     try:        assert 0  == 1, ' One does not equal zero '     except  assertionerror,e:        print  '%s:%s '  %  (e.__class__._ _name__,e) #assertdef  func9 (expr,args=none):     if __debug__ and not  EXPR:        RAISE ASSERTIONERROR,ARGSDEF FUNC10 ():     try:        float (' abc ')      except:        import sys         exect = sys. Exc_info ()         return exectdef func11 ():     try:        f = open (' Test.txt ')      except:        return None     ELSE:        RETURN FDEF FUNC12 ():     Try:        raw_input (' input data: ')      except  (Eoferror,keyboardinterrupt):        return  NONEIMPORT MATH,CMATHDEF SAFE_SQRT (data):    try:         RET = MATH.SQRT (data)     except ValueError:         RET = CMATH.SQRT (data)     return  Retimport sysdef func13 ():  &nbsP;  try:        s = raw_input (' Enter  Something--> ')     except EOFError:         print  ' \nwhy did you do an eof on me? '         sys.exit (0)     except:         print  ' \nsome error/exception occurred. '     print  ' Done ' func13 ()

This article is from the "XWB" blog, make sure to keep this source http://xiewb.blog.51cto.com/11091636/1792273

Python Basic Learning Code errors and exceptions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.