diff options
author | Prabhu Ramachandran | 2015-02-05 16:29:50 +0530 |
---|---|---|
committer | Prabhu Ramachandran | 2015-02-05 16:29:50 +0530 |
commit | dbc71e582f663bc79366bce9f87201d1212ac96a (patch) | |
tree | af518e93991946651769339ae06f02e8fe522d26 | |
parent | f5fbae8cf6385aaabfb111ec3502f6049d96f998 (diff) | |
download | sees-dbc71e582f663bc79366bce9f87201d1212ac96a.tar.gz sees-dbc71e582f663bc79366bce9f87201d1212ac96a.tar.bz2 sees-dbc71e582f663bc79366bce9f87201d1212ac96a.zip |
Add standalone script slide.
-rw-r--r-- | slides/basic_python/python_part2.tex | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/slides/basic_python/python_part2.tex b/slides/basic_python/python_part2.tex index 750a097..e0ca77e 100644 --- a/slides/basic_python/python_part2.tex +++ b/slides/basic_python/python_part2.tex @@ -191,6 +191,28 @@ def fib(n): # write Fibonacci series up to n \end{itemize} \end{frame} + +\begin{frame}[fragile] + \frametitle{Stand-alone scripts} +Consider a file \texttt{f.py}: +\footnotesize +\begin{lstlisting} +#!/usr/bin/env python +"""Module level documentation.""" +# First line tells the shell that it should use Python +# to interpret the code in the file. +def f(): + print "f" + +# Check if we are running standalone or as module. +# When imported, __name__ will not be '__main__' +if __name__ == '__main__': + # This is not executed when f.py is imported. + f() +\end{lstlisting} +\end{frame} + + \section{Exceptions} \begin{frame}{Motivation} |