135 \item can we have duplicate keys? |
135 \item can we have duplicate keys? |
136 \end{itemize} |
136 \end{itemize} |
137 \inctime{5} |
137 \inctime{5} |
138 \end{frame} |
138 \end{frame} |
139 |
139 |
140 \begin{frame} {Problem Set 2.1} |
140 \begin{frame} {Problem Set 6.1} |
141 \begin{description} |
141 \begin{description} |
142 \item[2.1.1] You are given date strings of the form ``29, Jul 2009'', or ``4 January 2008''. In other words a number a string and another number, with a comma sometimes separating the items.Write a function that takes such a string and returns a tuple (yyyy, mm, dd) where all three elements are ints. |
142 \item[6.1.1] You are given date strings of the form ``29, Jul 2009'', or ``4 January 2008''. In other words a number a string and another number, with a comma sometimes separating the items.Write a function that takes such a string and returns a tuple (yyyy, mm, dd) where all three elements are ints. |
143 \item[2.1.2] Count word frequencies in a file. |
143 \item[6.1.2] Count word frequencies in a file. |
144 \item[2.1.3] Find the most used Python keywords in your Python code (import keyword). |
144 \item[6.1.3] Find the most used Python keywords in your Python code (import keyword). |
145 \end{description} |
145 \end{description} |
146 |
146 |
147 \inctime{10} |
147 \inctime{10} |
148 \end{frame} |
148 \end{frame} |
149 |
149 |
308 |
311 |
309 \begin{frame}[fragile] |
312 \begin{frame}[fragile] |
310 \frametitle{Exceptions} |
313 \frametitle{Exceptions} |
311 \begin{lstlisting} |
314 \begin{lstlisting} |
312 >>> print spam |
315 >>> print spam |
|
316 \end{lstlisting} |
|
317 \pause |
|
318 \begin{lstlisting} |
313 Traceback (most recent call last): |
319 Traceback (most recent call last): |
314 File "<stdin>", line 1, in <module> |
320 File "<stdin>", line 1, in <module> |
315 NameError: name 'spam' is not defined |
321 NameError: name 'spam' is not defined |
316 |
322 \end{lstlisting} |
|
323 \end{frame} |
|
324 |
|
325 \begin{frame}[fragile] |
|
326 \frametitle{Exceptions} |
|
327 \begin{lstlisting} |
317 >>> 1 / 0 |
328 >>> 1 / 0 |
|
329 \end{lstlisting} |
|
330 \pause |
|
331 \begin{lstlisting} |
318 Traceback (most recent call last): |
332 Traceback (most recent call last): |
319 File "<stdin>", line 1, in <module> |
333 File "<stdin>", line 1, in <module> |
320 ZeroDivisionError: integer division |
334 ZeroDivisionError: integer division |
321 or modulo by zero |
335 or modulo by zero |
322 \end{lstlisting} |
336 \end{lstlisting} |
323 \end{frame} |
337 \end{frame} |
324 |
338 |
325 \begin{frame}[fragile] |
339 \begin{frame}[fragile] |
326 \frametitle{Debugging effectively} |
340 \frametitle{Debugging effectively} |
327 |
|
328 \begin{itemize} |
341 \begin{itemize} |
329 \item \kwrd{print} based strategy |
342 \item \kwrd{print} based strategy |
330 \item Process: Hypothesis, test, refine, rinse-repeat |
343 \item Process: Hypothesis, test, refine, rinse-repeat |
331 \item Using \typ{\%debug} and \typ{\%pdb} in IPython |
|
332 \end{itemize} |
344 \end{itemize} |
333 \end{frame} |
345 \inctime{15} |
334 |
346 \end{frame} |
335 \begin{frame}[fragile] |
347 |
336 \frametitle{Debugging: example} |
348 \begin{frame}[fragile] |
337 \small |
349 \frametitle{Debugging effectively} |
338 \begin{lstlisting} |
350 \begin{itemize} |
339 >>> import pdb |
351 \item Using \typ{\%debug} and \typ{\%pdb} in IPython |
340 >>> import mymodule |
352 \end{itemize} |
341 >>> pdb.run('mymodule.test()') |
353 \inctime{15} |
342 > <string>(1)<module>() |
|
343 (Pdb) continue |
|
344 Traceback (most recent call last): |
|
345 File "<stdin>", line 1, in <module> |
|
346 File "/usr/lib/python2.6/pdb.py", line 1207, in run |
|
347 Pdb().run(statement, globals, locals) |
|
348 File "/usr/lib/python2.6/bdb.py", line 368, in run |
|
349 exec cmd in globals, locals |
|
350 File "<string>", line 1, in <module> |
|
351 File "mymodule.py", line 2, in test |
|
352 print spam |
|
353 NameError: global name 'spam' is not defined |
|
354 \end{lstlisting} |
|
355 \end{frame} |
|
356 |
|
357 \begin{frame}[fragile] |
|
358 \frametitle{Debugging in IPython} |
|
359 \small |
|
360 \begin{lstlisting} |
|
361 In [1]: %pdb |
|
362 Automatic pdb calling has been turned ON |
|
363 In [2]: import mymodule |
|
364 In [3]: mymodule.test() |
|
365 ---------------------------------------------- |
|
366 NameError Traceback (most recent call last) |
|
367 /media/python/iitb/workshops/day1/<ipython console> in <module>() |
|
368 /media/python/iitb/workshops/day1/mymodule.pyc in test() |
|
369 1 def test(): |
|
370 ----> 2 print spam |
|
371 NameError: global name 'spam' is not defined |
|
372 > /media/python/iitb/workshops/day1/mymodule.py(2)test() |
|
373 0 print spam |
|
374 ipdb> |
|
375 \end{lstlisting} |
|
376 \inctime{15} |
|
377 \end{frame} |
354 \end{frame} |
378 |
355 |
379 \begin{frame}[fragile] |
356 \begin{frame}[fragile] |
380 \frametitle{Debugging: Exercise} |
357 \frametitle{Debugging: Exercise} |
381 \inctime{10} |
358 \inctime{10} |