diff options
Diffstat (limited to 'additional_ipython')
-rw-r--r-- | additional_ipython/quickref.tex | 15 | ||||
-rw-r--r-- | additional_ipython/script.rst | 219 | ||||
-rw-r--r-- | additional_ipython/slides.org | 90 | ||||
-rw-r--r-- | additional_ipython/slides.tex | 149 |
4 files changed, 0 insertions, 473 deletions
diff --git a/additional_ipython/quickref.tex b/additional_ipython/quickref.tex deleted file mode 100644 index 1616316..0000000 --- a/additional_ipython/quickref.tex +++ /dev/null @@ -1,15 +0,0 @@ -accessing history:\\ -{\ex \lstinline| \%hist|} - -accessing particular line of history:\\ -{\ex \lstinline| \%hist line_number|} - -accessing particular range of history:\\ -{\ex \lstinline| \%hist start_line stop_line|} - -saving history to a file:\\ -{\ex \lstinline| \%save file_path line_numbers|} - -running a script:\\ -{\ex \lstinline| \%run -i file_path|} - diff --git a/additional_ipython/script.rst b/additional_ipython/script.rst deleted file mode 100644 index 0b79cc6..0000000 --- a/additional_ipython/script.rst +++ /dev/null @@ -1,219 +0,0 @@ -.. Objectives -.. ---------- - -.. By the end of this tutorial you will be able to - -.. #. Retrieve your ipython history -.. #. View a part of the history -.. #. Save a part of your history to a file. -.. #. Run a script from within ipython - - -.. Prerequisites -.. ------------- - -.. 1. Embellishing Plots - -.. Author : Nishanth Amuluru - Internal Reviewer : Amit - External Reviewer : - Language Reviewer : Bhanukiran - Checklist OK? : <15-11-2010, Anand, OK> [2010-10-05] - -Script ------- - -Hello friends and welcome to the tutorial on Additional Features of IPython - -{{{ Show the slide containing title }}} - -{{{ Show the slide containing the outline slide }}} - -In this tutorial, we shall look at additional features of IPython that help us -to retreive the commands that we type on the interpreter and then save them -into a file and run it. - -Let us start ipython with pylab loaded, by typing -:: - - $ ipython -pylab - -on the terminal - -{{{ shift to terminal and type ipython -pylab }}} - -We shall first make a plot and then view the history and save it. -:: - - x = linspace(-2*pi, 2*pi, 100) - plot(x, xsinx(x)) - -xsin(x) is actually x * sin(x) -:: - - plot(x, x*sin(x)) - plot(x, sin(x)) - xlabel("x") - ylabel("$f(x)$") - title("x and xsin") - -We now have the plot. Let us look at the commands that we have typed in. The -history can be retreived by using =%hist= command. Type -:: - - %hist - -As you can see, it displays a list of recent commands that we typed. Every -command has a number in front, to specify in which order and when it was typed. - -Please note that there is a % sign before the hist command. This implies that -%hist is a command that is specific to IPython and not available in the vannila -Python interpreter. These type of commands are called as magic commands. - -Also note that, the =%hist= itself is a command and is displayed as the most -recent command. We should not that anything we type in is stored as history, -irrespective of whether it is command or an error or IPython magic command. - -If we want only the recent 5 commands to be displayed, we pass the number as an argument -to =%hist= command. Hence -:: - - %hist 5 - -displays the recent 5 commands, inclusive of the =%hist= command. -The default number is 40. - -{{{ Pause here and try out the following exercises }}} - -%% 1 %% Read through the documentation of %hist and find out how to - list all the commands between 5 and 10 - -{{{ continue from paused state }}} - -As we can see from =%hist= documentation, -:: - - %hist 5 10 - -displays the commands from 5 to 10 - -Now that we have the history, we would like to save the required line of code -from history. This is possible by using the =%save= command. - -Before we do that, let us first look at history and identify what lines of code we require.Type -:: - - %hist - - -{{{ point to the lines }}} - -The first command is linspace. But second command is a command that gave us an -error. Hence we do not need second command. The commands from third to sixth are -required. The seventh command although is correct, we do not need it since we -are setting the title correctly in the eigthth command. - -So we need first third to sixth and the eigthth command for our program. -Hence the syntax of =%save= is -:: - - %save /home/fossee/plot_script.py 1 3-6 8 - -{{{ point to the output of the command }}} - -The command saves first and then third to sixth and eighth lines of code into -the specified file. - -The first argument to %save is the path of file to save the commands and the -arguments there after are the commands to be saved in the given order. - -{{{ goto the file and open it and show it }}} - -{{{ Pause here and try out the following exercises }}} - -%% 2 %% Change the label on y-axis to "y" and save the lines of code - accordingly - -{{{ continue from paused state }}} - -we use the command =ylabel= on interpreter as -:: - - ylabel("y") - -and then do -:: - - %save /home/fossee/example_plot.py 1 3-6 10 - -Now that we have the required lines of code in a file, let us learn how to run -the file as a python script. - -We use the IPython magic command =%run= to do this. Type -:: - - %run -i /home/fossee/plot_script.py - -The script runs but we do not see the plot. This happens because when we are running -a script and we are not in interactive mode anymore. - -Hence on your terminal type -:: - - show() - -to show the plot. - -{{{ Pause here and try out the following exercises }}} - -%% 3 %% Use %hist and %save and create a script that has show in it and run it - to produce and show the plot. - - -{{{ continue from paused state }}} - -We first look at the history using -:: - - %hist 20 - -Then save the script using -:: - - %save /home/fossee/show_included.py 1 3-6 8 10 13 - %run -i /home/fossee/show_included.py - show() - -We get the desired plot. - -The reason for including a -i after run is to tell the interpreter that if any -name is not found in script, search for it in the interpreter. Hence all these -sin, plot, pi and show which are not available in script, are taken from the -interpreter and used to run the script. - -{{{ Pause here and try out the following exercises }}} - -%% 4 %% Run the script without using the -i option. Do you find any difference? - -{{{ continue from paused state }}} - -We see that it raises NameError saying that the name linspace is not found. - -{{{ Show summary slide }}} - -This brings us to the end of the tutorial. -we have looked at - - * Retreiving history using =%hist= command - * Vieweing only a part of history by passing an argument to %hist - * saving the required lines of code in required order using %save - * using %run -i command to run the saved script - -{{{ Show the "sponsored by FOSSEE" slide }}} - - -This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India - -Hope you have enjoyed and found it useful. -Thank You! - diff --git a/additional_ipython/slides.org b/additional_ipython/slides.org deleted file mode 100644 index 4b11b61..0000000 --- a/additional_ipython/slides.org +++ /dev/null @@ -1,90 +0,0 @@ -#+LaTeX_CLASS: beamer -#+LaTeX_CLASS_OPTIONS: [presentation] -#+BEAMER_FRAME_LEVEL: 1 - -#+BEAMER_HEADER_EXTRA: \usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent} -#+COLUMNS: %45ITEM %10BEAMER_env(Env) %10BEAMER_envargs(Env Args) %4BEAMER_col(Col) %8BEAMER_extra(Extra) -#+PROPERTY: BEAMER_col_ALL 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 :ETC - -#+LaTeX_CLASS: beamer -#+LaTeX_CLASS_OPTIONS: [presentation] - -#+LaTeX_HEADER: \usepackage[english]{babel} \usepackage{ae,aecompl} -#+LaTeX_HEADER: \usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet} - -#+LaTeX_HEADER:\usepackage{listings} - -#+LaTeX_HEADER:\lstset{language=Python, basicstyle=\ttfamily\bfseries, -#+LaTeX_HEADER: commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen}, -#+LaTeX_HEADER: showstringspaces=false, keywordstyle=\color{blue}\bfseries} - -#+TITLE: Additional Features of =ipython= -#+AUTHOR: FOSSEE -#+EMAIL: -#+DATE: - -#+DESCRIPTION: -#+KEYWORDS: -#+LANGUAGE: en -#+OPTIONS: H:3 num:nil toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t -#+OPTIONS: TeX:t LaTeX:nil skip:nil d:nil todo:nil pri:nil tags:not-in-toc - -* Outline - + Retrieving ipython history - + Viewing a part of the history - + Saving (relevant) parts of the history to a file - + Running a script from within ipython -* Question 1 - Read through the documentation of ~%hist~ and find out how to list - all the commands between 5 and 10 -* Solution 1 - #+begin_src python - In []: %hist 5 10 - #+end_src -* Question 2 - Change the label on y-axis to "y" and save the lines of code - accordingly -* Solution 2 - #+begin_src python - In []: ylabel("y") - In []: %save /home/fossee/example_plot.py 1 3-6 10 - #+end_src -* Question 3 - Use =%hist= and =%save= and create a script that has show in it and - run it to produce and show the plot. - -* Solution 3 - #+begin_src python - In []: %hist 20 - - In []: %save /home/fossee/show_included.py 1 3-6 8 10 13 - In []: %run -i /home/fossee/show_included.py - #+end_src -* Question 4 - Run the script without using the -i option. Do you find any - difference? -* Solution 4 - We see that it raises ~NameError~ saying the name ~linspace~ is not - found. -* Summary - + Retreiving history using =%hist= command - + Vieweing only a part of history by passing an argument to %hist - + Saving the required lines of code in required order using %save - + Using %run -i command to run the saved script - -* Thank you! -#+begin_latex - \begin{block}{} - \begin{center} - This spoken tutorial has been produced by the - \textcolor{blue}{FOSSEE} team, which is funded by the - \end{center} - \begin{center} - \textcolor{blue}{National Mission on Education through \\ - Information \& Communication Technology \\ - MHRD, Govt. of India}. - \end{center} - \end{block} -#+end_latex - - diff --git a/additional_ipython/slides.tex b/additional_ipython/slides.tex deleted file mode 100644 index b21fa3e..0000000 --- a/additional_ipython/slides.tex +++ /dev/null @@ -1,149 +0,0 @@ -% Created 2010-10-10 Sun 17:30 -\documentclass[presentation]{beamer} -\usepackage[latin1]{inputenc} -\usepackage[T1]{fontenc} -\usepackage{fixltx2e} -\usepackage{graphicx} -\usepackage{longtable} -\usepackage{float} -\usepackage{wrapfig} -\usepackage{soul} -\usepackage{textcomp} -\usepackage{marvosym} -\usepackage{wasysym} -\usepackage{latexsym} -\usepackage{amssymb} -\usepackage{hyperref} -\tolerance=1000 -\usepackage[english]{babel} \usepackage{ae,aecompl} -\usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet} -\usepackage{listings} -\lstset{language=Python, basicstyle=\ttfamily\bfseries, -commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen}, -showstringspaces=false, keywordstyle=\color{blue}\bfseries} -\providecommand{\alert}[1]{\textbf{#1}} - -\title{Additional Features of \texttt{ipython}} -\author{FOSSEE} -\date{} - -\usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent} -\begin{document} - -\maketitle - - - - - - - - - - -\begin{frame} -\frametitle{Outline} -\label{sec-1} - -\begin{itemize} -\item Retrieving ipython history -\item Viewing a part of the history -\item Saving (relevant) parts of the history to a file -\item Running a script from within ipython -\end{itemize} -\end{frame} -\begin{frame} -\frametitle{Question 1} -\label{sec-2} - - Read through the documentation of \texttt{\%hist} and find out how to list - all the commands between 5 and 10 -\end{frame} -\begin{frame}[fragile] -\frametitle{Solution 1} -\label{sec-3} - -\lstset{language=Python} -\begin{lstlisting} -In []: %hist 5 10 -\end{lstlisting} -\end{frame} -\begin{frame} -\frametitle{Question 2} -\label{sec-4} - - Change the label on y-axis to ``y'' and save the lines of code - accordingly -\end{frame} -\begin{frame}[fragile] -\frametitle{Solution 2} -\label{sec-5} - -\lstset{language=Python} -\begin{lstlisting} -In []: ylabel("y") -In []: %save /home/fossee/example_plot.py 1 3-6 10 -\end{lstlisting} -\end{frame} -\begin{frame} -\frametitle{Question 3} -\label{sec-6} - - Use \texttt{\%hist} and \texttt{\%save} and create a script that has show in it and - run it to produce and show the plot. -\end{frame} -\begin{frame}[fragile] -\frametitle{Solution 3} -\label{sec-7} - -\lstset{language=Python} -\begin{lstlisting} -In []: %hist 20 - -In []: %save /home/fossee/show_included.py 1 3-6 8 10 13 -In []: %run -i /home/fossee/show_included.py -\end{lstlisting} -\end{frame} -\begin{frame} -\frametitle{Question 4} -\label{sec-8} - - Run the script without using the -i option. Do you find any - difference? -\end{frame} -\begin{frame} -\frametitle{Solution 4} -\label{sec-9} - - We see that it raises \texttt{NameError} saying the name \texttt{linspace} is not - found. -\end{frame} -\begin{frame} -\frametitle{Summary} -\label{sec-10} - -\begin{itemize} -\item Retreiving history using \texttt{\%hist} command -\item Vieweing only a part of history by passing an argument to \%hist -\item Saving the required lines of code in required order using \%save -\item Using \%run -i command to run the saved script -\end{itemize} -\end{frame} -\begin{frame} -\frametitle{Thank you!} -\label{sec-11} - - \begin{block}{} - \begin{center} - This spoken tutorial has been produced by the - \textcolor{blue}{FOSSEE} team, which is funded by the - \end{center} - \begin{center} - \textcolor{blue}{National Mission on Education through \\ - Information \& Communication Technology \\ - MHRD, Govt. of India}. - \end{center} - \end{block} -\end{frame} - -\end{document} |