diff options
-rw-r--r-- | slides/advanced_python/advanced_py.tex | 10 | ||||
-rw-r--r-- | slides/advanced_python/slides/modules.tex | 66 |
2 files changed, 10 insertions, 66 deletions
diff --git a/slides/advanced_python/advanced_py.tex b/slides/advanced_python/advanced_py.tex index b15419e..0be43d6 100644 --- a/slides/advanced_python/advanced_py.tex +++ b/slides/advanced_python/advanced_py.tex @@ -50,4 +50,14 @@ showstringspaces=false, keywordstyle=\color{blue}\bfseries} \include{slides/scipy} \include{slides/modules} +\section{Other packages} + +\begin{frame}{Very useful packages} + \begin{itemize} + \item \url{http://ipython.org/} + \item \url{http://sympy.org/} + \item \url{http://pandas.pydata.org/} + \end{itemize} +\end{frame} + \end{document} diff --git a/slides/advanced_python/slides/modules.tex b/slides/advanced_python/slides/modules.tex index d6de640..707c3b3 100644 --- a/slides/advanced_python/slides/modules.tex +++ b/slides/advanced_python/slides/modules.tex @@ -94,70 +94,4 @@ \end{lstlisting} \end{frame} -\section{Writing modules} - -\begin{frame}[fragile] - \frametitle{GCD script} - \begin{itemize} - \item Function that computes gcd of two numbers - \item Save it as \texttt{gcd\_script.py} - \end{itemize} - \begin{lstlisting} - def gcd(a, b): - while b: - a, b = b, a%b - return a - \end{lstlisting} - \begin{itemize} - \item Also add the tests to the file - \end{itemize} - \begin{lstlisting} - if gcd(40, 12) == 4 and gcd(12, 13) == 1: - print "Everything OK" - else: - print "The GCD function is wrong" - \end{lstlisting} - \begin{lstlisting} - $ python gcd_script.py - \end{lstlisting} % $ -\end{frame} - -\begin{frame}[fragile] - \frametitle{Python path} - \begin{itemize} - \item In IPython type the following - \end{itemize} - \begin{lstlisting} - import sys - sys.path - \end{lstlisting} - \begin{itemize} - \item List of locations where python searches for a module - \item \texttt{import sys} -- searches for file \texttt{sys.py} or - dir \texttt{sys} in all these locations - \item So, our own modules can be in any one of the locations - \item Current working directory is one of the locations - \end{itemize} -\end{frame} - -\begin{frame}[fragile] - \frametitle{\texttt{\_\_name\_\_}} - \begin{lstlisting} - import gcd_script - \end{lstlisting} - \begin{itemize} - \item The import is successful - \item But the test code, gets run - \item Add the tests to the following \texttt{if} block - \end{itemize} - \begin{lstlisting} - if __name__ == "__main__": - \end{lstlisting} - \begin{itemize} - \item Now the script runs properly - \item As well as the import works; test code not executed - \item \texttt{\_\_name\_\_} is local to every module and is equal - to \texttt{\_\_main\_\_} only when the file is run as a script. - \end{itemize} -\end{frame} |