Added images for failure finding section
5
README.rst
Normal file
@@ -0,0 +1,5 @@
|
||||
Debugging Python
|
||||
================
|
||||
|
||||
This is a presentation about debugging, debuggers and the practical introduction
|
||||
to ``pdb``.
|
||||
@@ -121,18 +121,9 @@
|
||||
\end{itemize}
|
||||
\column{.4\textwidth}
|
||||
\centering
|
||||
\only<1>{\begin{figure}[!htbp]
|
||||
\includegraphics[width=3cm]{"images/find_bug.png"}
|
||||
\end{figure}
|
||||
}
|
||||
\only<2>{\begin{figure}[!htbp]
|
||||
\includegraphics[width=3cm]{images/debugs.png}
|
||||
\end{figure}
|
||||
}
|
||||
\only<3>{\begin{figure}[!htbp]
|
||||
\includegraphics[width=3cm]{images/pdb.png}
|
||||
\end{figure}
|
||||
}
|
||||
\only<1>{\includegraphics[width=3cm]{images/find_bug.png}}
|
||||
\only<2>{\includegraphics[width=3cm]{images/debugs.png}}
|
||||
\only<3>{\includegraphics[width=3cm]{images/pdb.png}}
|
||||
\end{columns}
|
||||
\end{frame}
|
||||
|
||||
@@ -142,17 +133,46 @@
|
||||
\endgroup
|
||||
|
||||
\begin{frame}
|
||||
\begin{itemize}
|
||||
\item{traceback (obviously)}
|
||||
\pause
|
||||
\item \lstinline{print} statement
|
||||
\pause
|
||||
\item module \lstinline{logging}
|
||||
\pause
|
||||
\item module \lstinline{trace}
|
||||
\pause
|
||||
\item debugger
|
||||
\begin{columns}
|
||||
\column{.5\textwidth}
|
||||
\begin{itemize}[<+->]
|
||||
\item<1,2,3,4,5> traceback (obviously)
|
||||
\item<2,3,4,5> \lstinline{print} statement
|
||||
\item<3,4,5> module \lstinline{logging}
|
||||
\item<4,5> module \lstinline{trace}
|
||||
\item<5> debugger
|
||||
\end{itemize}
|
||||
\column{.4\textwidth}
|
||||
\centering
|
||||
\only<1>{%
|
||||
|
||||
\vspace*{0cm}
|
||||
\hspace*{0cm}\includegraphics[width=5cm]{images/traceback.png}
|
||||
|
||||
}
|
||||
\only<2>{%
|
||||
|
||||
\vspace*{0cm}
|
||||
\hspace*{0cm}\includegraphics[width=5cm]{images/print.png}
|
||||
|
||||
}
|
||||
\only<3>{%
|
||||
|
||||
\vspace*{0cm}
|
||||
\hspace*{0cm}\includegraphics[width=5cm]{images/logging.png}
|
||||
|
||||
}
|
||||
\only<4>{%
|
||||
|
||||
\vspace*{0cm}
|
||||
\hspace*{0cm}\includegraphics[width=5cm]{images/trace.png}
|
||||
|
||||
}
|
||||
\only<5>{%
|
||||
\vspace*{0cm}
|
||||
\hspace*{0cm}\includegraphics[width=5cm]{images/pudb.png}
|
||||
}
|
||||
\end{columns}
|
||||
\end{frame}
|
||||
|
||||
\begingroup
|
||||
@@ -168,7 +188,7 @@
|
||||
\begin{itemize}[<+->]
|
||||
\item<1,2,3> Text based
|
||||
\item<2,3> Graphical
|
||||
\item<3> Embedded in IDE/editor
|
||||
\item<3> Embedded in IDE
|
||||
\end{itemize}
|
||||
\column{.4\textwidth}
|
||||
\end{columns}
|
||||
@@ -181,12 +201,15 @@
|
||||
\begin{itemize}
|
||||
\item \lstinline{pdb}
|
||||
\item \lstinline{ipdb}
|
||||
\item \lstinline{ripdb}
|
||||
\item \lstinline{pdb++}
|
||||
\item \lstinline{pupdb}
|
||||
\item \lstinline{pudb}
|
||||
\item \color{blue}\href{https://wiki.python.org/moin/PythonDebuggingTools}{\uline{others}}
|
||||
\end{itemize}
|
||||
\column{.5\textwidth}
|
||||
|
||||
\vspace*{0cm}
|
||||
\hspace*{0cm}\includegraphics[width=5cm]{"images/ipdb.png"}
|
||||
|
||||
\end{columns}
|
||||
\end{frame}
|
||||
|
||||
@@ -199,11 +222,15 @@
|
||||
\item \lstinline{pywin.debugger}
|
||||
\end{itemize}
|
||||
\column{.5\textwidth}
|
||||
|
||||
\vspace*{0cm}
|
||||
\hspace*{0cm}\includegraphics[width=5cm]{"images/winpdb.png"}
|
||||
|
||||
\end{columns}
|
||||
\end{frame}
|
||||
|
||||
\begin{frame}
|
||||
\frametitle{Debuggers - IDE/editors}
|
||||
\frametitle{Debuggers - IDE}
|
||||
\begin{columns}
|
||||
\column{.4\textwidth}
|
||||
\begin{itemize}
|
||||
@@ -214,6 +241,10 @@
|
||||
\item \color{blue}\href{https://wiki.python.org/moin/IntegratedDevelopmentEnvironments}{\uline{others!}}
|
||||
\end{itemize}
|
||||
\column{.5\textwidth}
|
||||
|
||||
\vspace*{0cm}
|
||||
\hspace*{0cm}\includegraphics[width=5cm]{"images/pycharm.png"}
|
||||
|
||||
\end{columns}
|
||||
\end{frame}
|
||||
|
||||
@@ -222,6 +253,26 @@
|
||||
\section{Python debugger - pdb}
|
||||
\endgroup
|
||||
|
||||
\begin{frame}
|
||||
\frametitle{cm2inch.py}
|
||||
\begin{itemize}
|
||||
\item Problem: Convert length in centimetre into inch and vice versa
|
||||
\item Solution: Simple TKinter program to do this
|
||||
\pause
|
||||
\item …But it doesn't work :(
|
||||
\end{itemize}
|
||||
\end{frame}
|
||||
|
||||
\begin{frame}
|
||||
\frametitle{cm2inch.py - structure}
|
||||
\begin{itemize}
|
||||
\item Single class defined - \lstinline{CmInchConverter}
|
||||
\item Method \lstinline{run} launches the program
|
||||
\item Method \lstinline{_gui_initialze} builds the GUI
|
||||
\item Method \lstinline{calculate} implements the actual calculation logic
|
||||
\end{itemize}
|
||||
\end{frame}
|
||||
|
||||
\begin{frame}
|
||||
\centerline{\Large Let see it in action!}
|
||||
\end{frame}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import Tkinter as tk
|
||||
import ttk
|
||||
|
||||
|
||||
class CmInchConverter(object):
|
||||
@@ -17,6 +16,32 @@ class CmInchConverter(object):
|
||||
self._gui_initialize()
|
||||
self._root.mainloop()
|
||||
|
||||
def calculate(self):
|
||||
"""Perform calculation"""
|
||||
action = {1: self._inch_calculate,
|
||||
2: self._cm_calculate}
|
||||
try:
|
||||
val = int(self.value.get())
|
||||
except ValueError:
|
||||
val = self.value.get()
|
||||
|
||||
result = action[self.convert_to_inches.get()](val)
|
||||
self.result.set(result)
|
||||
|
||||
def _inch_calculate(self, val):
|
||||
"""Calculate inch value from given val in cm"""
|
||||
try:
|
||||
return "%.4f" % val * 0.3937
|
||||
except TypeError:
|
||||
return "Err"
|
||||
|
||||
def _cm_calculate(self, val):
|
||||
"""Calculate cm value from given val in inch"""
|
||||
try:
|
||||
return "%.4f" % val/0.3937
|
||||
except TypeError:
|
||||
return "Err"
|
||||
|
||||
def _gui_initialize(self):
|
||||
"""Initialize the GUI"""
|
||||
self._root = tk.Tk()
|
||||
@@ -29,7 +54,7 @@ class CmInchConverter(object):
|
||||
self.value.set("0")
|
||||
self.result.set("0")
|
||||
|
||||
mainframe = ttk.Frame(self._root, padding="3 3 12 12")
|
||||
mainframe = tk.Frame(self._root, pady=5, padx=5)
|
||||
mainframe.grid(column=0, row=0, sticky=(tk.N, tk.W, tk.E, tk.S))
|
||||
mainframe.columnconfigure(0, weight=1)
|
||||
mainframe.rowconfigure(0, weight=1)
|
||||
@@ -49,49 +74,22 @@ class CmInchConverter(object):
|
||||
value=2)
|
||||
radio2.grid(column=0, row=3, columnspan=2, **defaults)
|
||||
|
||||
ttk.Label(mainframe, text="Enter value:").grid(column=0, row=1,
|
||||
tk.Label(mainframe, text="Enter value:").grid(column=0, row=1,
|
||||
**defaults)
|
||||
entry1 = ttk.Entry(mainframe, width=20, textvariable=self.value)
|
||||
entry1 = tk.Entry(mainframe, width=20, textvariable=self.value)
|
||||
entry1.grid(column=1, row=1, **defaults)
|
||||
|
||||
ttk.Label(mainframe, text="Result:").grid(column=0, row=4, **defaults)
|
||||
tk.Label(mainframe, text="Result:").grid(column=0, row=4, **defaults)
|
||||
|
||||
entry2 = tk.Entry(mainframe, width=20, state=tk.DISABLED,
|
||||
textvariable=self.result,
|
||||
disabledbackground="White Smoke",
|
||||
disabledforeground="Midnight Blue")
|
||||
entry2.grid(column=1, row=4, **defaults)
|
||||
ttk.Button(mainframe, text="Calculate",
|
||||
tk.Button(mainframe, text="Calculate",
|
||||
command=self.calculate).grid(column=3, row=5, **defaults)
|
||||
|
||||
|
||||
def calculate(self):
|
||||
"""Perform calculation"""
|
||||
action = {1: self._inch_calculate,
|
||||
2: self._cm_calculate}
|
||||
try:
|
||||
val = int(self.value.get())
|
||||
except ValueError:
|
||||
val = self.value.get()
|
||||
|
||||
result = action[self.convert_to_inches.get()](val)
|
||||
self.result.set(result)
|
||||
|
||||
def _cm_calculate(self, val):
|
||||
"""Calculate cm value from given val in inch"""
|
||||
try:
|
||||
return "%.4f" % val/0.3937
|
||||
except TypeError:
|
||||
return "Err"
|
||||
|
||||
def _inch_calculate(self, val):
|
||||
"""Calculate inch value from given val in cm"""
|
||||
try:
|
||||
return "%.4f" % val * 0.3937
|
||||
except TypeError:
|
||||
return "Err"
|
||||
|
||||
|
||||
def main():
|
||||
"""Main function"""
|
||||
conv = CmInchConverter()
|
||||
|
||||
BIN
images/dbg.png
Normal file
|
After Width: | Height: | Size: 23 KiB |
BIN
images/ipdb.png
Normal file
|
After Width: | Height: | Size: 27 KiB |
BIN
images/logging.png
Normal file
|
After Width: | Height: | Size: 31 KiB |
BIN
images/print.png
Normal file
|
After Width: | Height: | Size: 16 KiB |
BIN
images/pudb.png
Normal file
|
After Width: | Height: | Size: 33 KiB |
BIN
images/pycharm.png
Normal file
|
After Width: | Height: | Size: 98 KiB |
BIN
images/trace.png
Normal file
|
After Width: | Height: | Size: 25 KiB |
BIN
images/traceback.png
Normal file
|
After Width: | Height: | Size: 28 KiB |
BIN
images/winpdb.png
Normal file
|
After Width: | Height: | Size: 71 KiB |