<span id="7ztzv"></span>
<sub id="7ztzv"></sub>

<span id="7ztzv"></span><form id="7ztzv"></form>

<span id="7ztzv"></span>

        <address id="7ztzv"></address>

            ???? Python ???
            ??13?? ??
            ???? try..finally ????

            try..finally

            ???????????????????????????????????????????????????????????????????????finally??????¨À?????????try???¡ê???????????except????finally?î•???????????????????????????????????????

            ???finally

            ??13.3 ???finally

            #!/usr/bin/python
            # Filename: finally.py


            import time

            try:
                f =
            file('poem.txt')
                while True: # our usual file-reading idiom
                    line = f.readline()
                    if len(line) == 0:
                        break
                    time.sleep(2)
                    print line,
            finally:
                f.close()

                print 'Cleaning up...closed the file'

            ????????code/finally.py??

            ???

            $ python finally.py
            Programming is fun
            When the work is done
            Cleaning up...closed the file
            Traceback (most recent call last):
              File "finally.py", line 12, in ?
                time.sleep(2)
            KeyboardInterrupt

            ????¦É???

            ?????????????????????????????????????????????time.sleep???????2???????????????????¨®??????§Ö????§»??Python??????????????§Ö¨²????????????§Ö??????Ctrl-c?§Ø?/???????

            ?????????KeyboardInterrupt???????????????????????????????????finally??????????§µ?????????


            ???? ????? ????
            ?????? ??? ????
            ?????
            @ssv
            <span id="7ztzv"></span>
            <sub id="7ztzv"></sub>

            <span id="7ztzv"></span><form id="7ztzv"></form>

            <span id="7ztzv"></span>

                  <address id="7ztzv"></address>

                      ÑÇÖÞÅ·ÃÀÔÚÏß