Commits

Mark Lavin  committed 71df118

Slides for lecture 4.

  • Participants
  • Parent commits b9df449

Comments (0)

Files changed (4)

File code/output.py

+with open(__file__) as f:
+    print u''.join(f.readlines())

File code/withexample.py

+class Example(object):
+
+    def __enter__(self):
+        print "Calling Enter"
+        return 73
+
+    def __exit__(self, exc_type, exc_value, traceback):
+        print "Calling Exit: %s, %s, %s" % (
+            exc_type, exc_value, traceback
+        )
+        # This will stop the exception 
+        # from being propagated
+        return True 
+
+
+with Example() as ex:
+    print ex
+
+with Example() as ex:
+    raise Exception

File lectures/four.rst

     open_file.close()
 
 
+The File Object
+----------------------------------------
+
+Let's take a look at what methods are on the ``File`` type.
+
+.. code-block:: python
+    
+    dir(file)
+
+
 Opening File Safely
 ----------------------------------------
 
 Python 2.5. ``with`` is built-in to Python 2.6 and beyond.
 
 
+With Statement
+----------------------------------------
+
+To take a small detour let's talk about the ``with`` statement.
+
+The ``with`` statement is used to wrap a code block context manager. The
+context manager defines an ``__enter__`` to setup the context and ``__exit__``
+to clean up the code execution. The common use case is reusing try/except blocks
+for opening/closing resources.
+
+
+With Example (withexample.py)
+----------------------------------------
+
+.. literalinclude:: /code/withexample.py
+    :lines: 1-10
+
+
 Reading Files
 ----------------------------------------
 
             print line
 
 
+A Program Which Outputs Itself (output.py)
+-----------------------------------------------
+
+.. literalinclude:: /code/output.py
+
+
 Writing Files
 ----------------------------------------
 
         f.writelines(['Line 2\n', 'Line 3\n'])
 
 
+Appending Files
+----------------------------------------
+
+.. code-block:: python
+
+    with open('example.txt', 'w') as f:
+        f.write('First pass.\n')
+
+    with open('example.txt', 'a') as f:
+        f.write('This is new.\n')
+
+
 File Paths
 ----------------------------------------
 
 .. literalinclude:: /code/directory.py
 
 
-Handling Special File Types
+Modules Special File Types
 ----------------------------------------
 
-- Pickle
 - XML
+    - DOM (Document Object Model): ``xml.dom``
+    - SAX (Simple API for XML): ``xml.sax``
 - CSV
-- HTML
+
+
+Up Next
+----------------------------------------
+
+Functional programming in Python
 
 
 .. header:: 

File slides/Spring2011/four.pdf

+%PDF-1.4
+%���� ReportLab Generated PDF document http://www.reportlab.com
+1 0 obj
+<< /F1 2 0 R
+ /F2 3 0 R
+ /F3 7 0 R
+ /F4 8 0 R
+ /F5 12 0 R >>
+endobj
+2 0 obj
+<< /BaseFont /Helvetica
+ /Encoding /WinAnsiEncoding
+ /Name /F1
+ /Subtype /Type1
+ /Type /Font >>
+endobj
+3 0 obj
+<< /BaseFont /Helvetica-Bold
+ /Encoding /WinAnsiEncoding
+ /Name /F2
+ /Subtype /Type1
+ /Type /Font >>
+endobj
+4 0 obj
+<< /Contents 74 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 73 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+5 0 obj
+<< /Contents 75 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 73 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+6 0 obj
+<< /Contents 76 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 73 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+7 0 obj
+<< /BaseFont /Courier
+ /Encoding /WinAnsiEncoding
+ /Name /F3
+ /Subtype /Type1
+ /Type /Font >>
+endobj
+8 0 obj
+<< /BaseFont /Courier-Bold
+ /Encoding /WinAnsiEncoding
+ /Name /F4
+ /Subtype /Type1
+ /Type /Font >>
+endobj
+9 0 obj
+<< /Contents 77 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 73 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+10 0 obj
+<< /Contents 78 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 73 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+11 0 obj
+<< /Contents 79 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 73 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+12 0 obj
+<< /BaseFont /Courier-Oblique
+ /Encoding /WinAnsiEncoding
+ /Name /F5
+ /Subtype /Type1
+ /Type /Font >>
+endobj
+13 0 obj
+<< /Contents 80 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 73 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+14 0 obj
+<< /Contents 81 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 73 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+15 0 obj
+<< /Contents 82 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 73 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+16 0 obj
+<< /Contents 83 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 73 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+17 0 obj
+<< /A << /S /URI
+ /Type /Action
+ /URI (http://docs.python.org/library/exceptions.html) >>
+ /Border [ 0
+ 0
+ 0 ]
+ /Rect [ 111.8183
+ 101.1449
+ 270.5543
+ 113.1449 ]
+ /Subtype /Link
+ /Type /Annot >>
+endobj
+18 0 obj
+<< /Annots [ 17 0 R ]
+ /Contents 84 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 73 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+19 0 obj
+<< /Contents 85 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 73 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+20 0 obj
+<< /Contents 86 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 73 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+21 0 obj
+<< /Contents 87 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 73 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+22 0 obj
+<< /Contents 88 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 73 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+23 0 obj
+<< /Contents 89 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 73 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+24 0 obj
+<< /Contents 90 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 73 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+25 0 obj
+<< /Contents 91 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 73 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+26 0 obj
+<< /Contents 92 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 73 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+27 0 obj
+<< /Contents 93 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 73 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+28 0 obj
+<< /Contents 94 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 73 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+29 0 obj
+<< /Contents 95 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 73 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+30 0 obj
+<< /Contents 96 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 73 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+31 0 obj
+<< /Contents 97 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 73 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+32 0 obj
+<< /Contents 98 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 73 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+33 0 obj
+<< /Contents 99 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 73 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+34 0 obj
+<< /Contents 100 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 73 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+35 0 obj
+<< /Contents 101 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 73 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+36 0 obj
+<< /Contents 102 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 73 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+37 0 obj
+<< /Contents 103 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 73 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+38 0 obj
+<< /Contents 104 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 73 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+39 0 obj
+<< /Outlines 41 0 R
+ /PageLabels 105 0 R
+ /PageMode /UseNone
+ /Pages 73 0 R
+ /Type /Catalog >>
+endobj
+40 0 obj
+<< /Author ()
+ /CreationDate (D:20000101000000+00'00')
+ /Creator (\(unspecified\))
+ /Keywords ()
+ /Producer (ReportLab PDF Library - www.reportlab.com)
+ /Subject (\(unspecified\))
+ /Title () >>
+endobj
+41 0 obj
+<< /Count 31
+ /First 42 0 R
+ /Last 72 0 R
+ /Type /Outlines >>
+endobj
+42 0 obj
+<< /Dest [ 4 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 43 0 R
+ /Parent 41 0 R
+ /Title (Exceptions and File Handling) >>
+endobj
+43 0 obj
+<< /Dest [ 5 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 44 0 R
+ /Parent 41 0 R
+ /Prev 42 0 R
+ /Title (Understanding Exceptions) >>
+endobj
+44 0 obj
+<< /Dest [ 6 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 45 0 R
+ /Parent 41 0 R
+ /Prev 43 0 R
+ /Title (Same Code but Different Style) >>
+endobj
+45 0 obj
+<< /Dest [ 9 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 46 0 R
+ /Parent 41 0 R
+ /Prev 44 0 R
+ /Title (Look Before You Leap) >>
+endobj
+46 0 obj
+<< /Dest [ 10 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 47 0 R
+ /Parent 41 0 R
+ /Prev 45 0 R
+ /Title (Easier to Ask Forgiveness than Permission) >>
+endobj
+47 0 obj
+<< /Dest [ 11 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 48 0 R
+ /Parent 41 0 R
+ /Prev 46 0 R
+ /Title (Catching Exceptions) >>
+endobj
+48 0 obj
+<< /Dest [ 13 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 49 0 R
+ /Parent 41 0 R
+ /Prev 47 0 R
+ /Title (Skeleton Example) >>
+endobj
+49 0 obj
+<< /Dest [ 14 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 50 0 R
+ /Parent 41 0 R
+ /Prev 48 0 R
+ /Title (Catching Multiple Types of Exceptions) >>
+endobj
+50 0 obj
+<< /Dest [ 15 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 51 0 R
+ /Parent 41 0 R
+ /Prev 49 0 R
+ /Title (Handling Different Exceptions Differently) >>
+endobj
+51 0 obj
+<< /Dest [ 16 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 52 0 R
+ /Parent 41 0 R
+ /Prev 50 0 R
+ /Title (Getting Exception Info) >>
+endobj
+52 0 obj
+<< /Dest [ 18 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 53 0 R
+ /Parent 41 0 R
+ /Prev 51 0 R
+ /Title (Built-in Exceptions) >>
+endobj
+53 0 obj
+<< /Dest [ 19 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 54 0 R
+ /Parent 41 0 R
+ /Prev 52 0 R
+ /Title (Creating Exceptions) >>
+endobj
+54 0 obj
+<< /Dest [ 20 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 55 0 R
+ /Parent 41 0 R
+ /Prev 53 0 R
+ /Title (Creating Exceptions Expanded) >>
+endobj
+55 0 obj
+<< /Dest [ 21 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 56 0 R
+ /Parent 41 0 R
+ /Prev 54 0 R
+ /Title (Raising Exceptions) >>
+endobj
+56 0 obj
+<< /Dest [ 22 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 57 0 R
+ /Parent 41 0 R
+ /Prev 55 0 R
+ /Title (Raising Exceptions Again) >>
+endobj
+57 0 obj
+<< /Dest [ 23 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 58 0 R
+ /Parent 41 0 R
+ /Prev 56 0 R
+ /Title (Supporting Different Python Versions) >>
+endobj
+58 0 obj
+<< /Dest [ 24 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 59 0 R
+ /Parent 41 0 R
+ /Prev 57 0 R
+ /Title (Opening Files) >>
+endobj
+59 0 obj
+<< /Dest [ 25 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 60 0 R
+ /Parent 41 0 R
+ /Prev 58 0 R
+ /Title (The File Object) >>
+endobj
+60 0 obj
+<< /Dest [ 26 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 61 0 R
+ /Parent 41 0 R
+ /Prev 59 0 R
+ /Title (Opening File Safely) >>
+endobj
+61 0 obj
+<< /Dest [ 27 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 62 0 R
+ /Parent 41 0 R
+ /Prev 60 0 R
+ /Title (With Statement) >>
+endobj
+62 0 obj
+<< /Dest [ 28 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 63 0 R
+ /Parent 41 0 R
+ /Prev 61 0 R
+ /Title (With Example \(withexample.py\)) >>
+endobj
+63 0 obj
+<< /Dest [ 29 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 64 0 R
+ /Parent 41 0 R
+ /Prev 62 0 R
+ /Title (Reading Files) >>
+endobj
+64 0 obj
+<< /Dest [ 30 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 65 0 R
+ /Parent 41 0 R
+ /Prev 63 0 R
+ /Title (A Program Which Outputs Itself \(output.py\)) >>
+endobj
+65 0 obj
+<< /Dest [ 31 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 66 0 R
+ /Parent 41 0 R
+ /Prev 64 0 R
+ /Title (Writing Files) >>
+endobj
+66 0 obj
+<< /Dest [ 32 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 67 0 R
+ /Parent 41 0 R
+ /Prev 65 0 R
+ /Title (Appending Files) >>
+endobj
+67 0 obj
+<< /Dest [ 33 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 68 0 R
+ /Parent 41 0 R
+ /Prev 66 0 R
+ /Title (File Paths) >>
+endobj
+68 0 obj
+<< /Dest [ 34 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 69 0 R
+ /Parent 41 0 R
+ /Prev 67 0 R
+ /Title (File Paths Example \(filepath.py\)) >>
+endobj
+69 0 obj
+<< /Dest [ 35 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 70 0 R
+ /Parent 41 0 R
+ /Prev 68 0 R
+ /Title (Directories) >>
+endobj
+70 0 obj
+<< /Dest [ 36 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 71 0 R
+ /Parent 41 0 R
+ /Prev 69 0 R
+ /Title (Iterating over Directories \(directory.py\)) >>
+endobj
+71 0 obj
+<< /Dest [ 37 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 72 0 R
+ /Parent 41 0 R
+ /Prev 70 0 R
+ /Title (Modules Special File Types) >>
+endobj
+72 0 obj
+<< /Dest [ 38 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Parent 41 0 R
+ /Prev 71 0 R
+ /Title (Up Next) >>
+endobj
+73 0 obj
+<< /Count 31
+ /Kids [ 4 0 R
+ 5 0 R
+ 6 0 R
+ 9 0 R
+ 10 0 R
+ 11 0 R
+ 13 0 R
+ 14 0 R
+ 15 0 R
+ 16 0 R
+ 18 0 R
+ 19 0 R
+ 20 0 R
+ 21 0 R
+ 22 0 R
+ 23 0 R
+ 24 0 R
+ 25 0 R
+ 26 0 R
+ 27 0 R
+ 28 0 R
+ 29 0 R
+ 30 0 R
+ 31 0 R
+ 32 0 R
+ 33 0 R
+ 34 0 R
+ 35 0 R
+ 36 0 R
+ 37 0 R
+ 38 0 R ]
+ /Type /Pages >>
+endobj
+74 0 obj
+<< /Length 2214 >>
+stream
+1 0 0 1 0 0 cm  BT /F1 12 Tf 14.4 TL ET
+q
+1 0 0 1 51.35433 206.1449 cm
+q
+BT 1 0 0 1 0 2.8 Tm 16.8 TL /F2 14 Tf 0 0 0 rg (Exceptions and File Handling) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 200.1449 cm
+Q
+q
+1 0 0 1 51.35433 200.1449 cm
+Q
+q
+1 0 0 1 51.35433 188.1449 cm
+0 0 0 rg
+BT /F1 10 Tf 12 TL ET
+q
+1 0 0 1 6 -3 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 11.2 0 Td (\177) Tj T* -11.2 0 Td ET
+Q
+Q
+q
+1 0 0 1 23 -3 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL (Understanding Exceptions) Tj T* ET
+Q
+Q
+q
+Q
+Q
+q
+1 0 0 1 51.35433 188.1449 cm
+Q
+q
+1 0 0 1 51.35433 176.1449 cm
+0 0 0 rg
+BT /F1 10 Tf 12 TL ET
+q
+1 0 0 1 6 -3 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 11.2 0 Td (\177) Tj T* -11.2 0 Td ET
+Q
+Q
+q
+1 0 0 1 23 -3 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL (Handling Exceptions) Tj T* ET
+Q
+Q
+q
+Q
+Q
+q
+1 0 0 1 51.35433 176.1449 cm
+Q
+q
+1 0 0 1 51.35433 164.1449 cm
+0 0 0 rg
+BT /F1 10 Tf 12 TL ET
+q
+1 0 0 1 6 -3 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 11.2 0 Td (\177) Tj T* -11.2 0 Td ET
+Q
+Q
+q
+1 0 0 1 23 -3 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL (Defining Custom Exceptions) Tj T* ET
+Q
+Q
+q
+Q
+Q
+q
+1 0 0 1 51.35433 164.1449 cm
+Q
+q
+1 0 0 1 51.35433 152.1449 cm
+0 0 0 rg
+BT /F1 10 Tf 12 TL ET
+q
+1 0 0 1 6 -3 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 11.2 0 Td (\177) Tj T* -11.2 0 Td ET
+Q
+Q
+q
+1 0 0 1 23 -3 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL (Reading/Writing Files) Tj T* ET
+Q
+Q
+q
+Q
+Q
+q
+1 0 0 1 51.35433 152.1449 cm
+Q
+q
+1 0 0 1 51.35433 140.1449 cm
+0 0 0 rg
+BT /F1 10 Tf 12 TL ET
+q
+1 0 0 1 6 -3 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 11.2 0 Td (\177) Tj T* -11.2 0 Td ET
+Q
+Q
+q
+1 0 0 1 23 -3 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL (Navigating the File System) Tj T* ET
+Q
+Q
+q
+Q
+Q
+q
+1 0 0 1 51.35433 140.1449 cm
+Q
+q
+1 0 0 1 51.35433 140.1449 cm
+Q
+q
+1 0 0 1 0 243.1181 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 170.9637 0 Td (MA792K Spring 2011 Lecture 4) Tj T* -170.9637 0 Td ET
+Q
+Q
+q
+1 0 0 1 0 0 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 193.1437 0 Td (\251 Mark Lavin 2011) Tj T* -193.1437 0 Td ET
+Q
+Q
+ 
+endstream
+endobj
+75 0 obj
+<< /Length 735 >>
+stream
+1 0 0 1 0 0 cm  BT /F1 12 Tf 14.4 TL ET
+q
+1 0 0 1 51.35433 206.1449 cm
+q
+BT 1 0 0 1 0 2.8 Tm 16.8 TL /F2 14 Tf 0 0 0 rg (Understanding Exceptions) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 176.1449 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 16 Tm /F1 8 Tf 12 TL .283087 Tw (Things do not always go as planned. If you don't want your program to just crash you'll need to be) Tj T* 0 Tw (able to handle exceptions.) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 176.1449 cm
+Q
+q
+1 0 0 1 0 243.1181 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 170.9637 0 Td (MA792K Spring 2011 Lecture 4) Tj T* -170.9637 0 Td ET
+Q
+Q
+q
+1 0 0 1 0 0 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 193.1437 0 Td (\251 Mark Lavin 2011) Tj T* -193.1437 0 Td ET
+Q
+Q
+ 
+endstream
+endobj
+76 0 obj
+<< /Length 990 >>
+stream
+1 0 0 1 0 0 cm  BT /F1 12 Tf 14.4 TL ET
+q
+1 0 0 1 51.35433 206.1449 cm
+q
+BT 1 0 0 1 0 2.8 Tm 16.8 TL /F2 14 Tf 0 0 0 rg (Same Code but Different Style) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 188.1449 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL (You have a couple options.) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 158.1449 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 16 Tm /F1 8 Tf 12 TL .475165 Tw (In some cases you can do some preliminary checks to make sure that your code will successfully) Tj T* 0 Tw (execute.) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 140.1449 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL (Or you can dive in an catch errors as they happen.) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 140.1449 cm
+Q
+q
+1 0 0 1 0 243.1181 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 170.9637 0 Td (MA792K Spring 2011 Lecture 4) Tj T* -170.9637 0 Td ET
+Q
+Q
+q
+1 0 0 1 0 0 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 193.1437 0 Td (\251 Mark Lavin 2011) Tj T* -193.1437 0 Td ET
+Q
+Q
+ 
+endstream
+endobj
+77 0 obj
+<< /Length 1075 >>
+stream
+1 0 0 1 0 0 cm  BT /F1 12 Tf 14.4 TL ET
+q
+1 0 0 1 51.35433 206.1449 cm
+q
+BT 1 0 0 1 0 2.8 Tm 16.8 TL /F2 14 Tf 0 0 0 rg (Look Before You Leap) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 148.9449 cm
+q
+q
+q
+1 0 0 1 6.6 6.6 cm
+q
+.662745 .662745 .662745 RG
+.5 w
+.960784 .960784 .862745 rg
+n -6 -6 349.6346 48 re B*
+Q
+q
+BT 1 0 0 1 0 28 Tm 12 TL /F3 8 Tf 0 0 0 rg (c) Tj ( ) Tj .4 .4 .4 rg (=) Tj 0 0 0 rg ( ) Tj .4 .4 .4 rg (200) Tj 0 0 0 rg  T* /F4 8 Tf 0 .501961 0 rg (if) Tj /F3 8 Tf 0 0 0 rg ( ) Tj (a) Tj ( ) Tj .4 .4 .4 rg (!=) Tj 0 0 0 rg ( ) Tj .4 .4 .4 rg (0) Tj 0 0 0 rg (:) Tj  T* (    ) Tj (c) Tj ( ) Tj .4 .4 .4 rg (=) Tj 0 0 0 rg ( ) Tj .4 .4 .4 rg (200) Tj 0 0 0 rg ( ) Tj .4 .4 .4 rg (/) Tj 0 0 0 rg ( ) Tj (a) Tj T* ET
+Q
+Q
+Q
+Q
+Q
+q
+1 0 0 1 51.35433 140.9449 cm
+Q
+q
+1 0 0 1 0 243.1181 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 170.9637 0 Td (MA792K Spring 2011 Lecture 4) Tj T* -170.9637 0 Td ET
+Q
+Q
+q
+1 0 0 1 0 0 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 193.1437 0 Td (\251 Mark Lavin 2011) Tj T* -193.1437 0 Td ET
+Q
+Q
+ 
+endstream
+endobj
+78 0 obj
+<< /Length 1209 >>
+stream
+1 0 0 1 0 0 cm  BT /F1 12 Tf 14.4 TL ET
+q
+1 0 0 1 51.35433 206.1449 cm
+q
+BT 1 0 0 1 0 2.8 Tm 16.8 TL /F2 14 Tf 0 0 0 rg (Easier to Ask Forgiveness than Permission) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 124.9449 cm
+q
+q
+q
+1 0 0 1 6.6 6.6 cm
+q
+.662745 .662745 .662745 RG
+.5 w
+.960784 .960784 .862745 rg
+n -6 -6 349.6346 72 re B*
+Q
+q
+BT 1 0 0 1 0 52 Tm 12 TL /F3 8 Tf 0 0 0 rg (c) Tj ( ) Tj .4 .4 .4 rg (=) Tj 0 0 0 rg ( ) Tj .4 .4 .4 rg (200) Tj 0 0 0 rg  T* /F4 8 Tf 0 .501961 0 rg (try) Tj /F3 8 Tf 0 0 0 rg (:) Tj  T* (    ) Tj (c) Tj ( ) Tj .4 .4 .4 rg (=) Tj 0 0 0 rg ( ) Tj .4 .4 .4 rg (200) Tj 0 0 0 rg ( ) Tj .4 .4 .4 rg (/) Tj 0 0 0 rg ( ) Tj (a) Tj  T* /F4 8 Tf 0 .501961 0 rg (except) Tj /F3 8 Tf 0 0 0 rg ( ) Tj /F4 8 Tf .823529 .254902 .227451 rg (ZeroDivisionError) Tj /F3 8 Tf 0 0 0 rg (:) Tj  T* (    ) Tj /F4 8 Tf 0 .501961 0 rg (pass) Tj T* ET
+Q
+Q
+Q
+Q
+Q
+q
+1 0 0 1 51.35433 116.9449 cm
+Q
+q
+1 0 0 1 0 243.1181 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 170.9637 0 Td (MA792K Spring 2011 Lecture 4) Tj T* -170.9637 0 Td ET
+Q
+Q
+q
+1 0 0 1 0 0 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 193.1437 0 Td (\251 Mark Lavin 2011) Tj T* -193.1437 0 Td ET
+Q
+Q
+ 
+endstream
+endobj
+79 0 obj
+<< /Length 1189 >>
+stream
+1 0 0 1 0 0 cm  BT /F1 12 Tf 14.4 TL ET
+q
+1 0 0 1 51.35433 206.1449 cm
+q
+BT 1 0 0 1 0 2.8 Tm 16.8 TL /F2 14 Tf 0 0 0 rg (Catching Exceptions) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 176.1449 cm
+q
+BT 1 0 0 1 0 16 Tm 1.215618 Tw 12 TL /F1 8 Tf 0 0 0 rg (The ) Tj /F3 8 Tf (try ) Tj /F1 8 Tf (keyword starts the block where exceptions are to be handled. The ) Tj /F3 8 Tf (except ) Tj /F1 8 Tf (keyword) Tj T* 0 Tw (denotes which exception classes are handled.) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 134.1449 cm
+q
+BT 1 0 0 1 0 28 Tm 2.169165 Tw 12 TL /F1 8 Tf 0 0 0 rg (You can also define an ) Tj /F3 8 Tf (else ) Tj /F1 8 Tf (block which will only excute if no exceptions were raised. A) Tj T* 0 Tw .132443 Tw /F3 8 Tf (finally ) Tj /F1 8 Tf (block is also optional and will be excuted regardless of whether there were exceptions or) Tj T* 0 Tw (not.) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 134.1449 cm
+Q
+q
+1 0 0 1 0 243.1181 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 170.9637 0 Td (MA792K Spring 2011 Lecture 4) Tj T* -170.9637 0 Td ET
+Q
+Q
+q
+1 0 0 1 0 0 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 193.1437 0 Td (\251 Mark Lavin 2011) Tj T* -193.1437 0 Td ET
+Q
+Q
+ 
+endstream
+endobj
+80 0 obj
+<< /Length 1199 >>
+stream
+1 0 0 1 0 0 cm  BT /F1 12 Tf 14.4 TL ET
+q
+1 0 0 1 51.35433 206.1449 cm
+q
+BT 1 0 0 1 0 2.8 Tm 16.8 TL /F2 14 Tf 0 0 0 rg (Skeleton Example) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 88.94488 cm
+q
+q
+q
+1 0 0 1 6.6 6.6 cm
+q
+.662745 .662745 .662745 RG
+.5 w
+.960784 .960784 .862745 rg
+n -6 -6 349.6346 108 re B*
+Q
+q
+BT 1 0 0 1 0 88 Tm 12 TL /F3 8 Tf 0 0 0 rg (try:) Tj  T* (    ) Tj /F5 8 Tf .25098 .501961 .501961 rg (# Something dangerous) Tj /F3 8 Tf 0 0 0 rg  T* (except) Tj ( ) Tj (IndexError:) Tj  T* (    ) Tj /F5 8 Tf .25098 .501961 .501961 rg (# Handle the error) Tj /F3 8 Tf 0 0 0 rg  T* /F4 8 Tf 0 .501961 0 rg (else) Tj /F3 8 Tf 0 0 0 rg (:) Tj  T* (    ) Tj /F5 8 Tf .25098 .501961 .501961 rg (# No problems so do something) Tj /F3 8 Tf 0 0 0 rg  T* (finally:) Tj  T* (    ) Tj /F5 8 Tf .25098 .501961 .501961 rg (# Clean up either way) Tj T* ET
+Q
+Q
+Q
+Q
+Q
+q
+1 0 0 1 51.35433 80.94488 cm
+Q
+q
+1 0 0 1 0 243.1181 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 170.9637 0 Td (MA792K Spring 2011 Lecture 4) Tj T* -170.9637 0 Td ET
+Q
+Q
+q
+1 0 0 1 0 0 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 193.1437 0 Td (\251 Mark Lavin 2011) Tj T* -193.1437 0 Td ET
+Q
+Q
+ 
+endstream
+endobj
+81 0 obj
+<< /Length 1151 >>
+stream
+1 0 0 1 0 0 cm  BT /F1 12 Tf 14.4 TL ET
+q
+1 0 0 1 51.35433 206.1449 cm
+q
+BT 1 0 0 1 0 2.8 Tm 16.8 TL /F2 14 Tf 0 0 0 rg (Catching Multiple Types of Exceptions) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 188.1449 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL (You can handle multiple types of exceptions in one except block.) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 118.9449 cm
+q
+q
+q
+1 0 0 1 6.6 6.6 cm
+q
+.662745 .662745 .662745 RG
+.5 w
+.960784 .960784 .862745 rg
+n -6 -6 349.6346 60 re B*
+Q
+q
+BT 1 0 0 1 0 40 Tm 12 TL /F3 8 Tf 0 0 0 rg (try:) Tj  T* (    ) Tj /F5 8 Tf .25098 .501961 .501961 rg (# Something dangerous) Tj /F3 8 Tf 0 0 0 rg  T* (except) Tj ( ) Tj (\() Tj (TypeError) Tj (,) Tj ( ) Tj (IndexError) Tj (\):) Tj  T* (    ) Tj /F5 8 Tf .25098 .501961 .501961 rg (# Handle either type) Tj T* ET
+Q
+Q
+Q
+Q
+Q
+q
+1 0 0 1 51.35433 110.9449 cm
+Q
+q
+1 0 0 1 0 243.1181 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 170.9637 0 Td (MA792K Spring 2011 Lecture 4) Tj T* -170.9637 0 Td ET
+Q
+Q
+q
+1 0 0 1 0 0 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 193.1437 0 Td (\251 Mark Lavin 2011) Tj T* -193.1437 0 Td ET
+Q
+Q
+ 
+endstream
+endobj
+82 0 obj
+<< /Length 1388 >>
+stream
+1 0 0 1 0 0 cm  BT /F1 12 Tf 14.4 TL ET
+q
+1 0 0 1 51.35433 206.1449 cm
+q
+BT 1 0 0 1 0 2.8 Tm 16.8 TL /F2 14 Tf 0 0 0 rg (Handling Different Exceptions Differently) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 188.1449 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL (You can also define multiple except cases to handle different exception types in different ways.) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 70.94488 cm
+q
+q
+q
+1 0 0 1 6.6 6.6 cm
+q
+.662745 .662745 .662745 RG
+.5 w
+.960784 .960784 .862745 rg
+n -6 -6 349.6346 108 re B*
+Q
+q
+BT 1 0 0 1 0 88 Tm 12 TL /F3 8 Tf 0 0 0 rg (try:) Tj  T* (    ) Tj /F5 8 Tf .25098 .501961 .501961 rg (# Something dangerous) Tj /F3 8 Tf 0 0 0 rg  T* (except) Tj ( ) Tj (TypeError:) Tj  T* (    ) Tj /F5 8 Tf .25098 .501961 .501961 rg (# Handle type error) Tj /F3 8 Tf 0 0 0 rg  T* (except) Tj ( ) Tj (IndexError:) Tj  T* (    ) Tj /F5 8 Tf .25098 .501961 .501961 rg (# Handle index error) Tj /F3 8 Tf 0 0 0 rg  T* (except:) Tj  T* (    ) Tj /F5 8 Tf .25098 .501961 .501961 rg (# Handle all other types) Tj T* ET
+Q
+Q
+Q
+Q
+Q
+q
+1 0 0 1 51.35433 62.94488 cm
+Q
+q
+1 0 0 1 0 243.1181 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 170.9637 0 Td (MA792K Spring 2011 Lecture 4) Tj T* -170.9637 0 Td ET
+Q
+Q
+q
+1 0 0 1 0 0 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 193.1437 0 Td (\251 Mark Lavin 2011) Tj T* -193.1437 0 Td ET
+Q
+Q
+ 
+endstream
+endobj
+83 0 obj
+<< /Length 1156 >>
+stream
+1 0 0 1 0 0 cm  BT /F1 12 Tf 14.4 TL ET
+q
+1 0 0 1 51.35433 206.1449 cm
+q
+BT 1 0 0 1 0 2.8 Tm 16.8 TL /F2 14 Tf 0 0 0 rg (Getting Exception Info) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 112.9449 cm
+q
+q
+q
+1 0 0 1 6.6 6.6 cm
+q
+.662745 .662745 .662745 RG
+.5 w
+.960784 .960784 .862745 rg
+n -6 -6 349.6346 84 re B*
+Q
+q
+BT 1 0 0 1 0 64 Tm 12 TL /F3 8 Tf 0 0 0 rg (try:) Tj  T* (    ) Tj /F5 8 Tf .25098 .501961 .501961 rg (# Something dangerous) Tj /F3 8 Tf 0 0 0 rg  T* (except) Tj ( ) Tj (TypeError) Tj ( ) Tj (as) Tj ( ) Tj (e:) Tj  T* (    ) Tj /F4 8 Tf 0 .501961 0 rg (print) Tj /F3 8 Tf 0 0 0 rg ( ) Tj (e) Tj  T* (    ) Tj /F4 8 Tf 0 .501961 0 rg (print) Tj /F3 8 Tf 0 0 0 rg ( ) Tj (e) Tj .4 .4 .4 rg (.) Tj 0 0 0 rg (args) Tj  T* (    ) Tj /F5 8 Tf .25098 .501961 .501961 rg (# Handle type error) Tj T* ET
+Q
+Q
+Q
+Q
+Q
+q
+1 0 0 1 51.35433 104.9449 cm
+Q
+q
+1 0 0 1 0 243.1181 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 170.9637 0 Td (MA792K Spring 2011 Lecture 4) Tj T* -170.9637 0 Td ET
+Q
+Q
+q
+1 0 0 1 0 0 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 193.1437 0 Td (\251 Mark Lavin 2011) Tj T* -193.1437 0 Td ET
+Q
+Q
+ 
+endstream
+endobj
+84 0 obj
+<< /Length 3008 >>
+stream
+1 0 0 1 0 0 cm  BT /F1 12 Tf 14.4 TL ET
+q
+1 0 0 1 51.35433 206.1449 cm
+q
+BT 1 0 0 1 0 2.8 Tm 16.8 TL /F2 14 Tf 0 0 0 rg (Built-in Exceptions) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 188.1449 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL (Some common exception classes:) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 188.1449 cm
+Q
+q
+1 0 0 1 51.35433 188.1449 cm
+Q
+q
+1 0 0 1 51.35433 176.1449 cm
+0 0 0 rg
+BT /F1 10 Tf 12 TL ET
+q
+1 0 0 1 6 -3 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 11.2 0 Td (\177) Tj T* -11.2 0 Td ET
+Q
+Q
+q
+1 0 0 1 23 -3 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL (Exception - Base exception class) Tj T* ET
+Q
+Q
+q
+Q
+Q
+q
+1 0 0 1 51.35433 176.1449 cm
+Q
+q
+1 0 0 1 51.35433 164.1449 cm
+0 0 0 rg
+BT /F1 10 Tf 12 TL ET
+q
+1 0 0 1 6 -3 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 11.2 0 Td (\177) Tj T* -11.2 0 Td ET
+Q
+Q
+q
+1 0 0 1 23 -3 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL (AttributeError - Attempted to access an object attribute that doesn't exist) Tj T* ET
+Q
+Q
+q
+Q
+Q
+q
+1 0 0 1 51.35433 164.1449 cm
+Q
+q
+1 0 0 1 51.35433 152.1449 cm
+0 0 0 rg
+BT /F1 10 Tf 12 TL ET
+q
+1 0 0 1 6 -3 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 11.2 0 Td (\177) Tj T* -11.2 0 Td ET
+Q
+Q
+q
+1 0 0 1 23 -3 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL (IOError - I/O related error \(file not found, disk full, etc\)) Tj T* ET
+Q
+Q
+q
+Q
+Q
+q
+1 0 0 1 51.35433 152.1449 cm
+Q
+q
+1 0 0 1 51.35433 140.1449 cm
+0 0 0 rg
+BT /F1 10 Tf 12 TL ET
+q
+1 0 0 1 6 -3 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 11.2 0 Td (\177) Tj T* -11.2 0 Td ET
+Q
+Q
+q
+1 0 0 1 23 -3 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL (ImportError - Module import error) Tj T* ET
+Q
+Q
+q
+Q
+Q
+q
+1 0 0 1 51.35433 140.1449 cm
+Q
+q
+1 0 0 1 51.35433 128.1449 cm
+0 0 0 rg
+BT /F1 10 Tf 12 TL ET
+q
+1 0 0 1 6 -3 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 11.2 0 Td (\177) Tj T* -11.2 0 Td ET
+Q
+Q
+q
+1 0 0 1 23 -3 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL (IndexError - Accessing index outside of list) Tj T* ET
+Q
+Q
+q
+Q
+Q
+q
+1 0 0 1 51.35433 128.1449 cm
+Q
+q
+1 0 0 1 51.35433 116.1449 cm
+0 0 0 rg
+BT /F1 10 Tf 12 TL ET
+q
+1 0 0 1 6 -3 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 11.2 0 Td (\177) Tj T* -11.2 0 Td ET
+Q
+Q
+q
+1 0 0 1 23 -3 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL (KeyError - Accessing dictionary key that doesn't exist) Tj T* ET
+Q
+Q
+q
+Q
+Q
+q
+1 0 0 1 51.35433 116.1449 cm
+Q
+q
+1 0 0 1 51.35433 98.14488 cm
+q
+BT 1 0 0 1 0 4 Tm 12 TL /F1 8 Tf 0 0 0 rg (For a full list see ) Tj 0 0 .501961 rg (http://docs.python.org/library/exceptions.html) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 98.14488 cm
+Q
+q
+1 0 0 1 0 243.1181 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 170.9637 0 Td (MA792K Spring 2011 Lecture 4) Tj T* -170.9637 0 Td ET
+Q
+Q
+q
+1 0 0 1 0 0 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 193.1437 0 Td (\251 Mark Lavin 2011) Tj T* -193.1437 0 Td ET
+Q
+Q
+ 
+endstream
+endobj
+85 0 obj
+<< /Length 1096 >>
+stream
+1 0 0 1 0 0 cm  BT /F1 12 Tf 14.4 TL ET
+q
+1 0 0 1 51.35433 206.1449 cm
+q
+BT 1 0 0 1 0 2.8 Tm 16.8 TL /F2 14 Tf 0 0 0 rg (Creating Exceptions) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 188.1449 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL (Creating exceptions is as easy as creating a class.) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 142.9449 cm
+q
+q
+q
+1 0 0 1 6.6 6.6 cm
+q
+.662745 .662745 .662745 RG
+.5 w
+.960784 .960784 .862745 rg
+n -6 -6 349.6346 36 re B*
+Q
+q
+BT 1 0 0 1 0 16 Tm 12 TL /F4 8 Tf 0 .501961 0 rg (class) Tj /F3 8 Tf 0 0 0 rg ( ) Tj /F4 8 Tf 0 0 1 rg (EveryonePanicException) Tj /F3 8 Tf 0 0 0 rg (\() Tj /F4 8 Tf .823529 .254902 .227451 rg (Exception) Tj /F3 8 Tf 0 0 0 rg (\):) Tj  T* (    ) Tj /F4 8 Tf 0 .501961 0 rg (pass) Tj T* ET
+Q
+Q
+Q
+Q
+Q
+q
+1 0 0 1 51.35433 134.9449 cm
+Q
+q
+1 0 0 1 0 243.1181 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 170.9637 0 Td (MA792K Spring 2011 Lecture 4) Tj T* -170.9637 0 Td ET
+Q
+Q
+q
+1 0 0 1 0 0 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 193.1437 0 Td (\251 Mark Lavin 2011) Tj T* -193.1437 0 Td ET
+Q
+Q
+ 
+endstream
+endobj
+86 0 obj
+<< /Length 1835 >>
+stream
+1 0 0 1 0 0 cm  BT /F1 12 Tf 14.4 TL ET
+q
+1 0 0 1 51.35433 206.1449 cm
+q
+BT 1 0 0 1 0 2.8 Tm 16.8 TL /F2 14 Tf 0 0 0 rg (Creating Exceptions Expanded) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 188.1449 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL (As with any class you can also pass additional information into your exceptions.) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 94.94488 cm
+q
+q
+q
+1 0 0 1 6.6 6.6 cm
+q
+.662745 .662745 .662745 RG
+.5 w
+.960784 .960784 .862745 rg
+n -6 -6 349.6346 84 re B*
+Q
+q
+BT 1 0 0 1 0 64 Tm 12 TL /F4 8 Tf 0 .501961 0 rg (class) Tj /F3 8 Tf 0 0 0 rg ( ) Tj /F4 8 Tf 0 0 1 rg (EveryonePanicException) Tj /F3 8 Tf 0 0 0 rg (\() Tj /F4 8 Tf .823529 .254902 .227451 rg (Exception) Tj /F3 8 Tf 0 0 0 rg (\):) Tj  T* (    ) Tj /F4 8 Tf 0 .501961 0 rg (def) Tj /F3 8 Tf 0 0 0 rg ( ) Tj 0 0 1 rg (__init__) Tj 0 0 0 rg (\() Tj 0 .501961 0 rg (self) Tj 0 0 0 rg (,) Tj ( ) Tj (reason) Tj (\):) Tj  T* (        ) Tj 0 .501961 0 rg (self) Tj .4 .4 .4 rg (.) Tj 0 0 0 rg (reason) Tj  T*  T* (    ) Tj /F4 8 Tf 0 .501961 0 rg (def) Tj /F3 8 Tf 0 0 0 rg ( ) Tj 0 0 1 rg (__str__) Tj 0 0 0 rg (\() Tj 0 .501961 0 rg (self) Tj 0 0 0 rg (\):) Tj  T* (        ) Tj /F4 8 Tf 0 .501961 0 rg (return) Tj /F3 8 Tf 0 0 0 rg ( ) Tj .729412 .129412 .129412 rg ('Everyone panic! ) Tj /F4 8 Tf .733333 .4 .533333 rg (%s) Tj /F3 8 Tf .729412 .129412 .129412 rg (') Tj 0 0 0 rg ( ) Tj .4 .4 .4 rg (%) Tj 0 0 0 rg ( ) Tj 0 .501961 0 rg (self) Tj .4 .4 .4 rg (.) Tj 0 0 0 rg (reason) Tj T* ET
+Q
+Q
+Q
+Q
+Q
+q
+1 0 0 1 51.35433 86.94488 cm
+Q
+q
+1 0 0 1 0 243.1181 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 170.9637 0 Td (MA792K Spring 2011 Lecture 4) Tj T* -170.9637 0 Td ET
+Q
+Q
+q
+1 0 0 1 0 0 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 193.1437 0 Td (\251 Mark Lavin 2011) Tj T* -193.1437 0 Td ET
+Q
+Q
+ 
+endstream
+endobj
+87 0 obj
+<< /Length 1035 >>
+stream
+1 0 0 1 0 0 cm  BT /F1 12 Tf 14.4 TL ET
+q
+1 0 0 1 51.35433 206.1449 cm
+q
+BT 1 0 0 1 0 2.8 Tm 16.8 TL /F2 14 Tf 0 0 0 rg (Raising Exceptions) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 188.1449 cm
+q
+BT 1 0 0 1 0 4 Tm 12 TL /F1 8 Tf 0 0 0 rg (The ) Tj /F3 8 Tf (raise ) Tj /F1 8 Tf (keyword is used to raise the specified exception.) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 154.9449 cm
+q
+q
+q
+1 0 0 1 6.6 6.6 cm
+q
+.662745 .662745 .662745 RG
+.5 w
+.960784 .960784 .862745 rg
+n -6 -6 349.6346 24 re B*
+Q
+q
+BT 1 0 0 1 0 4 Tm 12 TL /F4 8 Tf 0 .501961 0 rg (raise) Tj /F3 8 Tf 0 0 0 rg ( ) Tj (EveryonePanicException) Tj (\() Tj .729412 .129412 .129412 rg ("It's Godzilla!") Tj 0 0 0 rg (\)) Tj T* ET
+Q
+Q
+Q
+Q
+Q
+q
+1 0 0 1 51.35433 146.9449 cm
+Q
+q
+1 0 0 1 0 243.1181 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 170.9637 0 Td (MA792K Spring 2011 Lecture 4) Tj T* -170.9637 0 Td ET
+Q
+Q
+q
+1 0 0 1 0 0 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 193.1437 0 Td (\251 Mark Lavin 2011) Tj T* -193.1437 0 Td ET
+Q
+Q
+ 
+endstream
+endobj
+88 0 obj
+<< /Length 1485 >>
+stream
+1 0 0 1 0 0 cm  BT /F1 12 Tf 14.4 TL ET
+q
+1 0 0 1 51.35433 206.1449 cm
+q
+BT 1 0 0 1 0 2.8 Tm 16.8 TL /F2 14 Tf 0 0 0 rg (Raising Exceptions Again) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 176.1449 cm
+q
+BT 1 0 0 1 0 16 Tm 2.057665 Tw 12 TL /F1 8 Tf 0 0 0 rg (If you've caught an exception that you don't intend to handle then you can re-raise the last) Tj T* 0 Tw (exception with ) Tj /F3 8 Tf (raise) Tj /F1 8 Tf (.) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 94.94488 cm
+q
+q
+q
+1 0 0 1 6.6 6.6 cm
+q
+.662745 .662745 .662745 RG
+.5 w
+.960784 .960784 .862745 rg
+n -6 -6 349.6346 72 re B*
+Q
+q
+BT 1 0 0 1 0 52 Tm 12 TL /F4 8 Tf 0 .501961 0 rg (try) Tj /F3 8 Tf 0 0 0 rg (:) Tj  T* (    ) Tj /F4 8 Tf 0 .501961 0 rg (raise) Tj /F3 8 Tf 0 0 0 rg ( ) Tj (EveryonePanicException) Tj (\() Tj .729412 .129412 .129412 rg ("It's Godzilla!") Tj 0 0 0 rg (\)) Tj  T* /F4 8 Tf 0 .501961 0 rg (except) Tj /F3 8 Tf 0 0 0 rg ( ) Tj (EveryonePanicException) Tj (:) Tj  T* (    ) Tj /F4 8 Tf 0 .501961 0 rg (print) Tj /F3 8 Tf 0 0 0 rg ( ) Tj .729412 .129412 .129412 rg ("There was an exception.") Tj 0 0 0 rg  T* (    ) Tj /F4 8 Tf 0 .501961 0 rg (raise) Tj T* ET
+Q
+Q
+Q
+Q
+Q
+q
+1 0 0 1 51.35433 86.94488 cm
+Q
+q
+1 0 0 1 0 243.1181 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 170.9637 0 Td (MA792K Spring 2011 Lecture 4) Tj T* -170.9637 0 Td ET
+Q
+Q
+q
+1 0 0 1 0 0 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 193.1437 0 Td (\251 Mark Lavin 2011) Tj T* -193.1437 0 Td ET
+Q
+Q
+ 
+endstream
+endobj
+89 0 obj
+<< /Length 1546 >>
+stream
+1 0 0 1 0 0 cm  BT /F1 12 Tf 14.4 TL ET
+q
+1 0 0 1 51.35433 206.1449 cm
+q
+BT 1 0 0 1 0 2.8 Tm 16.8 TL /F2 14 Tf 0 0 0 rg (Supporting Different Python Versions) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 176.1449 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 16 Tm /F1 8 Tf 12 TL .212165 Tw (json module was added in Python 2.6 but simplejson is popular third party library. Here we'll check) Tj T* 0 Tw (if they have the json module and if not we'll try to use simplejson instead.) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 106.9449 cm
+q
+q
+q
+1 0 0 1 6.6 6.6 cm
+q
+.662745 .662745 .662745 RG
+.5 w
+.960784 .960784 .862745 rg
+n -6 -6 349.6346 60 re B*
+Q
+q
+BT 1 0 0 1 0 40 Tm 12 TL /F4 8 Tf 0 .501961 0 rg (try) Tj /F3 8 Tf 0 0 0 rg (:) Tj  T* (    ) Tj /F4 8 Tf 0 .501961 0 rg (import) Tj /F3 8 Tf 0 0 0 rg ( ) Tj /F4 8 Tf 0 0 1 rg (json) Tj /F3 8 Tf 0 0 0 rg  T* /F4 8 Tf 0 .501961 0 rg (except) Tj /F3 8 Tf 0 0 0 rg ( ) Tj /F4 8 Tf .823529 .254902 .227451 rg (ImportError) Tj /F3 8 Tf 0 0 0 rg (:) Tj  T* (    ) Tj /F4 8 Tf 0 .501961 0 rg (import) Tj /F3 8 Tf 0 0 0 rg ( ) Tj /F4 8 Tf 0 0 1 rg (simplejson) Tj /F3 8 Tf 0 0 0 rg ( ) Tj /F4 8 Tf 0 .501961 0 rg (as) Tj /F3 8 Tf 0 0 0 rg ( ) Tj /F4 8 Tf 0 0 1 rg (json) Tj T* ET
+Q
+Q
+Q
+Q
+Q
+q
+1 0 0 1 51.35433 98.94488 cm
+Q
+q
+1 0 0 1 0 243.1181 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 170.9637 0 Td (MA792K Spring 2011 Lecture 4) Tj T* -170.9637 0 Td ET
+Q
+Q
+q
+1 0 0 1 0 0 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 193.1437 0 Td (\251 Mark Lavin 2011) Tj T* -193.1437 0 Td ET
+Q
+Q
+ 
+endstream
+endobj
+90 0 obj
+<< /Length 1543 >>
+stream
+1 0 0 1 0 0 cm  BT /F1 12 Tf 14.4 TL ET
+q
+1 0 0 1 51.35433 206.1449 cm
+q