Commit 3f77f907 authored by Michael Kohlhase's avatar Michael Kohlhase

draining

parent 5edd07ee
\begin{module}[id=python-exceptions]
\importmhmodule[repos=MiKoMH/KWARC,path=missing/en/pseudocode]{pseudocode}
\importmhmodule[path=python/en/nutshell]{python-nutshell}
\importmhmodule[path=python/en/methods]{python-methods}
\lstset{language=python}
\begin{frame}[fragile]
\frametitle{How to deal with Errors in $\pythonLanguage$}
......@@ -12,12 +12,12 @@
\item<2->
\begin{definition}[id=SML-exception.def]
An \defi{exception} is a special $\pythonLanguage$
object. \defii[name=exception-raising]{Raising}{an exception} $e$ terminates
computation and returns $e$ to the next level.
\trefi[python-methods]{object}. \Defi{raising} an exception $e$ terminates
computation and passes $e$ to the next higher level.
\end{definition}
\item<3->
\begin{example}[title=Division by Zero]
the $\pythonLanguage$ interpreter reports unhandled \trefis{exception}
The $\pythonLanguage$ interpreter reports unhandled \trefis{exception}
\begin{onlyenv}<3>
\begin{lstlisting}
>>> -3 / 0
......@@ -27,33 +27,38 @@ Zerodivisionerror: division by zero
\end{lstlisting}
\end{onlyenv}
\end{example}
\item
\item<4->
\begin{omtext}
Exceptions are first-class citizens in $\pythonLanguage$, in particular they
\Trefis{exception} are first-class citizens in $\pythonLanguage$, in particular they
\begin{itemize}
\item can be defined by the user\lec{classes that inherit from \lstinline|exception|}
\item are classified by their \atrefi[python-methods]{classes}{class} in a hierarchy.
\item \trefi{excpetion} \atrefi[python-methods]{classes}{class} can be defined by
the user\lec{they inherit from the \lstinline|Exception| class}
\begin{onlyenv}<4>
\begin{lstlisting}
class DivByZero (Exception)
pass
\end{lstlisting}
\end{onlyenv}
\item can be raised when an abnormal condition appears
\begin{onlyenv}<5>
\end{onlyenv}
\item<5-> can be \atrefi{raised}{raising} when an abnormal condition appears
\begin{onlyenv}<5>
\begin{lstlisting}[mathescape]
if denominator == 0 :
raise DivByZero
else
$\pmetavar{computation}$
\end{lstlisting}
\end{onlyenv}
\item can be handled in a \lstinline|try|/\lstinline|except| block
\begin{onlyenv}<6>
\end{onlyenv}
\item<6-> can be \inlinedef{\adefi{handled}{handling} in a
\lstinline|try|/\lstinline|except| block}\lec{there can be multiple}
\begin{onlyenv}<6>
\begin{lstlisting}[mathescape]
try:
$\pmetavar{tentative computation}$
except: $\pmetavar{err}_1$, $\ldots$, $\pmetavar{err}_n$ :
except : $\pmetavar{err}_1$, $\ldots$, $\pmetavar{err}_n$ :
$\pmetavar{errorhandling}$
finally :
$\pmetavar{cleanup}$
\end{lstlisting}
\end{onlyenv}
\end{itemize}
......
\begin{module}[id=python-nutshell]
\importmhmodule[repos=MiKoMH/GenICT,path=programming/en/program-execution]{program-execution}
\importmhmodule[repos=MiKoMH/KWARC,path=missing/en/pseudocode]{pseudocode}
\symdef{pythonLanguage}{\text{\textsf{python}}}
\symdef{idlethree}{\text{\textsf{IDLE3}}}
\begin{nomtext}
......@@ -42,13 +43,14 @@
different syntax}
\begin{itemize}
\item install $\pythonLanguage$ from \url{http://python.org}\lec{for offline use}
\item make sure (tick box) that the \lstinline|python| executable is added to the
path.\lec{makes shell interaction much easier}
\end{itemize}
\end{omtext}
\end{itemize}
\end{frame}
\begin{note}
\begin{omtext}[title=Installing $\pythonLanguage$]
\begin{nomtext}[title=Installing $\pythonLanguage$]
\usemhmodule[repos=MiKoMH/KWARC,path=missing/en/operatingsystems]{operatingsystems}
$\pythonLanguage$ can be installed from \url{http://python.org} \ergo
``Downloads'', as a $\windowsOS$ installer or a $\macosxOS$ disk image. For $\linuxOS$
......@@ -61,8 +63,22 @@ sudo apt-get install python3.7
The download will install the $\pythonLanguage$ \trefi[program-execution]{interpreter} and
the $\pythonLanguage$ shell $\idlethree$ that can be used for interacting with the
\trefi[program-execution]{interpreter} directly.
\end{omtext}
\end{note}
\end{nomtext}
\begin{nomtext}
It is important that you make sure (tick the box in the Windows installer) that the
\lstinline|python| executable is added to the path. In the shell\ednote{fully introduce
the concept of a shell in the next round}, you can then use
\begin{lstlisting}[language=bash,mathescape]
python $\pmetavar{filename}$
\end{lstlisting}
to run the python file $\pmetavar{fiename}$. This is better than using the
windows-specific
\begin{lstlisting}[language=bash,mathescape]
py $\pmetavar{filename}$
\end{lstlisting}
which does not need the \lstinline|python| interpreter on the path as we will see later.
\end{nomtext}
\end{module}
%%% Local Variables:
%%% mode: latex
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment