1
0
mirror of https://github.com/gryf/debugging_python.git synced 2025-12-17 03:20:29 +01:00

Added images for failure finding section

This commit is contained in:
2015-06-28 17:12:18 +02:00
parent 21ce98d4bc
commit 60fb3e33d5
12 changed files with 116 additions and 62 deletions

5
README.rst Normal file
View File

@@ -0,0 +1,5 @@
Debugging Python
================
This is a presentation about debugging, debuggers and the practical introduction
to ``pdb``.

View File

@@ -121,18 +121,9 @@
\end{itemize} \end{itemize}
\column{.4\textwidth} \column{.4\textwidth}
\centering \centering
\only<1>{\begin{figure}[!htbp] \only<1>{\includegraphics[width=3cm]{images/find_bug.png}}
\includegraphics[width=3cm]{"images/find_bug.png"} \only<2>{\includegraphics[width=3cm]{images/debugs.png}}
\end{figure} \only<3>{\includegraphics[width=3cm]{images/pdb.png}}
}
\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}
}
\end{columns} \end{columns}
\end{frame} \end{frame}
@@ -142,17 +133,46 @@
\endgroup \endgroup
\begin{frame} \begin{frame}
\begin{itemize} \begin{columns}
\item{traceback (obviously)} \column{.5\textwidth}
\pause \begin{itemize}[<+->]
\item \lstinline{print} statement \item<1,2,3,4,5> traceback (obviously)
\pause \item<2,3,4,5> \lstinline{print} statement
\item module \lstinline{logging} \item<3,4,5> module \lstinline{logging}
\pause \item<4,5> module \lstinline{trace}
\item module \lstinline{trace} \item<5> debugger
\pause \end{itemize}
\item debugger \column{.4\textwidth}
\end{itemize} \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} \end{frame}
\begingroup \begingroup
@@ -168,7 +188,7 @@
\begin{itemize}[<+->] \begin{itemize}[<+->]
\item<1,2,3> Text based \item<1,2,3> Text based
\item<2,3> Graphical \item<2,3> Graphical
\item<3> Embedded in IDE/editor \item<3> Embedded in IDE
\end{itemize} \end{itemize}
\column{.4\textwidth} \column{.4\textwidth}
\end{columns} \end{columns}
@@ -181,12 +201,15 @@
\begin{itemize} \begin{itemize}
\item \lstinline{pdb} \item \lstinline{pdb}
\item \lstinline{ipdb} \item \lstinline{ipdb}
\item \lstinline{ripdb}
\item \lstinline{pdb++} \item \lstinline{pdb++}
\item \lstinline{pupdb} \item \lstinline{pudb}
\item \color{blue}\href{https://wiki.python.org/moin/PythonDebuggingTools}{\uline{others}} \item \color{blue}\href{https://wiki.python.org/moin/PythonDebuggingTools}{\uline{others}}
\end{itemize} \end{itemize}
\column{.5\textwidth} \column{.5\textwidth}
\vspace*{0cm}
\hspace*{0cm}\includegraphics[width=5cm]{"images/ipdb.png"}
\end{columns} \end{columns}
\end{frame} \end{frame}
@@ -199,11 +222,15 @@
\item \lstinline{pywin.debugger} \item \lstinline{pywin.debugger}
\end{itemize} \end{itemize}
\column{.5\textwidth} \column{.5\textwidth}
\vspace*{0cm}
\hspace*{0cm}\includegraphics[width=5cm]{"images/winpdb.png"}
\end{columns} \end{columns}
\end{frame} \end{frame}
\begin{frame} \begin{frame}
\frametitle{Debuggers - IDE/editors} \frametitle{Debuggers - IDE}
\begin{columns} \begin{columns}
\column{.4\textwidth} \column{.4\textwidth}
\begin{itemize} \begin{itemize}
@@ -214,6 +241,10 @@
\item \color{blue}\href{https://wiki.python.org/moin/IntegratedDevelopmentEnvironments}{\uline{others!}} \item \color{blue}\href{https://wiki.python.org/moin/IntegratedDevelopmentEnvironments}{\uline{others!}}
\end{itemize} \end{itemize}
\column{.5\textwidth} \column{.5\textwidth}
\vspace*{0cm}
\hspace*{0cm}\includegraphics[width=5cm]{"images/pycharm.png"}
\end{columns} \end{columns}
\end{frame} \end{frame}
@@ -222,6 +253,26 @@
\section{Python debugger - pdb} \section{Python debugger - pdb}
\endgroup \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} \begin{frame}
\centerline{\Large Let see it in action!} \centerline{\Large Let see it in action!}
\end{frame} \end{frame}

View File

@@ -1,5 +1,4 @@
import Tkinter as tk import Tkinter as tk
import ttk
class CmInchConverter(object): class CmInchConverter(object):
@@ -17,6 +16,32 @@ class CmInchConverter(object):
self._gui_initialize() self._gui_initialize()
self._root.mainloop() 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): def _gui_initialize(self):
"""Initialize the GUI""" """Initialize the GUI"""
self._root = tk.Tk() self._root = tk.Tk()
@@ -29,7 +54,7 @@ class CmInchConverter(object):
self.value.set("0") self.value.set("0")
self.result.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.grid(column=0, row=0, sticky=(tk.N, tk.W, tk.E, tk.S))
mainframe.columnconfigure(0, weight=1) mainframe.columnconfigure(0, weight=1)
mainframe.rowconfigure(0, weight=1) mainframe.rowconfigure(0, weight=1)
@@ -49,49 +74,22 @@ class CmInchConverter(object):
value=2) value=2)
radio2.grid(column=0, row=3, columnspan=2, **defaults) 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) **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) 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, entry2 = tk.Entry(mainframe, width=20, state=tk.DISABLED,
textvariable=self.result, textvariable=self.result,
disabledbackground="White Smoke", disabledbackground="White Smoke",
disabledforeground="Midnight Blue") disabledforeground="Midnight Blue")
entry2.grid(column=1, row=4, **defaults) 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) 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(): def main():
"""Main function""" """Main function"""
conv = CmInchConverter() conv = CmInchConverter()

BIN
images/dbg.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

BIN
images/ipdb.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

BIN
images/logging.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

BIN
images/print.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

BIN
images/pudb.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

BIN
images/pycharm.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

BIN
images/trace.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

BIN
images/traceback.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

BIN
images/winpdb.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB