diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..e07972b --- /dev/null +++ b/README.rst @@ -0,0 +1,5 @@ +Debugging Python +================ + +This is a presentation about debugging, debuggers and the practical introduction +to ``pdb``. diff --git a/debugging_python.tex b/debugging_python.tex index 4b8161e..f8f3bf2 100644 --- a/debugging_python.tex +++ b/debugging_python.tex @@ -72,7 +72,7 @@ } \setbeamertemplate{custom section} -{% +{% \begin{centering} \usebeamerfont{section title} \Large\bfseries @@ -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 - \end{itemize} + \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 @@ -166,9 +186,9 @@ \begin{columns} \column{.5\textwidth} \begin{itemize}[<+->] - \item<1,2,3> Text based + \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} diff --git a/example/cm2inch.py b/example/cm2inch.py index f5c8c3f..c5c7b55 100644 --- a/example/cm2inch.py +++ b/example/cm2inch.py @@ -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() diff --git a/images/dbg.png b/images/dbg.png new file mode 100644 index 0000000..7ad4bae Binary files /dev/null and b/images/dbg.png differ diff --git a/images/ipdb.png b/images/ipdb.png new file mode 100644 index 0000000..f54f51d Binary files /dev/null and b/images/ipdb.png differ diff --git a/images/logging.png b/images/logging.png new file mode 100644 index 0000000..6ad2d6f Binary files /dev/null and b/images/logging.png differ diff --git a/images/print.png b/images/print.png new file mode 100644 index 0000000..479aca3 Binary files /dev/null and b/images/print.png differ diff --git a/images/pudb.png b/images/pudb.png new file mode 100644 index 0000000..e6ddafb Binary files /dev/null and b/images/pudb.png differ diff --git a/images/pycharm.png b/images/pycharm.png new file mode 100644 index 0000000..fd3947f Binary files /dev/null and b/images/pycharm.png differ diff --git a/images/trace.png b/images/trace.png new file mode 100644 index 0000000..97b43da Binary files /dev/null and b/images/trace.png differ diff --git a/images/traceback.png b/images/traceback.png new file mode 100644 index 0000000..5b2e19d Binary files /dev/null and b/images/traceback.png differ diff --git a/images/winpdb.png b/images/winpdb.png new file mode 100644 index 0000000..5ce5f36 Binary files /dev/null and b/images/winpdb.png differ