INFO1110 Lecture Notes - Lecture 3: Order Of Merit
Document Summary
Python supports context managers using the with keyword. By opening a le with the with keyword, python will know to close the le after you leave the with block. with open("sample. txt", "r") as f: print(f. readline()) print(f. readline()) # the file will be closed outside the with block. ---> 4 print(f. readline()) # the file will be closed outside the with block. An exception is an object that signals an unusual occurrence during execution. When the exception object is created, it is termed throwing an exception" (or in. Some common exceptions you can catch: typeerror, valueerror, filenotfounderror. A typeerror happens when you give a function the wrong type. value = int([2, 3]) # the int function expects a string.