Recently in the follow Mooc learning Python, as a novice will encounter a lot of problems, such as the file read and write when the file is open to normal or not close the problem of the use of try...finally ..., after looking for information, it is understood, then the small part to talk about their views:
===============================
= = = Try...finally ... Use format:
Try
f = open (' Name.txt ', ' R ')
While True:
Program...
Finally
F.close ()
===============================
= = = below to see a specific code of operation
Try:
f = open (' Names.txt ')
While True:
line = F.read ()
If Len (line) ==0:
Break
Print Line
Finally
F.close ()
===============================
Check the information on the Internet when you see the Time.sleep (t) module, the main role is to delay the T-second output, of course, you need to add the import time statement at the beginning of the program, try...finally ... Is the content of the exception handling file, which ensures that the file will be close regardless of whether it is opened normally.
===============================
Explanation of the not in place want everyone to explore
Try...finally in Python ... The understanding