summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--additional_features_of_ipython/script.rst261
-rw-r--r--getting_started_with_ipython/slides.org80
-rw-r--r--using_plot_interactively/slides.org15
3 files changed, 287 insertions, 69 deletions
diff --git a/additional_features_of_ipython/script.rst b/additional_features_of_ipython/script.rst
index 0b79cc6..a7bd2ca 100644
--- a/additional_features_of_ipython/script.rst
+++ b/additional_features_of_ipython/script.rst
@@ -23,32 +23,58 @@
Script
------
-Hello friends and welcome to the tutorial on Additional Features of IPython
+.. L1
-{{{ Show the slide containing title }}}
+{{{ Show the first slide containing title, name of the production
+team along with the logo of MHRD }}}
+
+.. R1
+
+Hello friends and welcome to the tutorial on "Additional Features of IPython".
+
+.. L2
{{{ 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.
+.. R2
-Let us start ipython with pylab loaded, by typing
-::
+At the end of this tutorial, you will be able to,
+
+ 1. 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.
+
+.. R3
- $ ipython -pylab
+Let us start ipython with pylab loaded, by typing ipython -pylab on the terminal.
-on the terminal
+.. L3
{{{ shift to terminal and type ipython -pylab }}}
+::
+
+ ipython -pylab
+
+.. R4
+
We shall first make a plot and then view the history and save it.
+
+.. L4
+
::
x = linspace(-2*pi, 2*pi, 100)
plot(x, xsinx(x))
+.. R5
+
+We got an error saying "xsinx is not defined".This is because
xsin(x) is actually x * sin(x)
+
+.. L5
+
::
plot(x, x*sin(x))
@@ -57,133 +83,211 @@ xsin(x) is actually x * sin(x)
ylabel("$f(x)$")
title("x and xsin")
+.. R6
+
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
+history can be retreived by using =%hist= command.Type %hist in your terminal.
+
+.. L6
+
::
%hist
+.. R7
+
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.
+%hist is a command that is specific to IPython only and not to any other version of python.
+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.
+.. L7
+
+.. R8
+
If we want only the recent 5 commands to be displayed, we pass the number as an argument
-to =%hist= command. Hence
+to =%hist= command. Hence %hist 5 displays the recent 5 commands, inclusive of the =%hist= command.
+The default number is 40.
+
+.. L8
+
::
%hist 5
-displays the recent 5 commands, inclusive of the =%hist= command.
-The default number is 40.
+.. R9
+
+Pause here and try out the following exercise
+
+ Read through the documentation of %hist and find out how to
+ list all the commands between 5 and 10.
-{{{ Pause here and try out the following exercises }}}
+.. L9
-%% 1 %% Read through the documentation of %hist and find out how to
- list all the commands between 5 and 10
+.. L10
{{{ continue from paused state }}}
-As we can see from =%hist= documentation,
::
%hist 5 10
-displays the commands from 5 to 10
+.. R10
+
+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
+.. R11
+
+Before we do that, let us first look at history and identify what lines of code we require.Type %hist again.
+
+.. L11
+
::
%hist
+.. L12
{{{ point to the lines }}}
+.. R12
+
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.
+are setting the title correctly in the eighth command.
+
+.. R13
+
+So we need first third to sixth and the eighth command for our program.
+Hence the syntax of =%save= will be
+
+.. L13
+
+{{{ Type as you say }}}
-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
+.. L14
+
{{{ point to the output of the command }}}
-The command saves first and then third to sixth and eighth lines of code into
+.. R14
+
+The command saves the first line of code and then third to sixth followed by the 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.
+.. L15
+
{{{ goto the file and open it and show it }}}
-{{{ Pause here and try out the following exercises }}}
+.. R15
+
+.. R16
+
+Pause here and try out the following exercise
+
+ Change the label on y-axis to "y" and save the lines of code accordingly.
-%% 2 %% Change the label on y-axis to "y" and save the lines of code
- accordingly
+.. L16
+
+.. L17
{{{ continue from paused state }}}
-we use the command =ylabel= on interpreter as
::
ylabel("y")
+.. R17
+
+we use the command =ylabel= on interpreter
+
+.. R18
+
and then do
+
+.. L18
+
+{{{Type as you say}}}
+
::
%save /home/fossee/example_plot.py 1 3-6 10
+.. R19
+
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
+
+.. L19
+
::
- %run -i /home/fossee/plot_script.py
+ %run -i /home/fossee/plot_script.py
+
+.. R20
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
+Hence to view the plot type ``show()`` on your terminal
+
+.. L20
+
::
show()
-to show the plot.
-
-{{{ Pause here and try out the following exercises }}}
+.. R21
-%% 3 %% Use %hist and %save and create a script that has show in it and run it
- to produce and show the plot.
+Pause here and try out the following exercise
+ 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 }}}
+<Pause>
We first look at the history using
+
+.. L21
+
::
%hist 20
+.. R22
+
Then save the script using
+
+.. L22
+
+{{{ Say as you type }}}
+
::
%save /home/fossee/show_included.py 1 3-6 8 10 13
%run -i /home/fossee/show_included.py
show()
+.. R23
+
We get the desired plot.
The reason for including a -i after run is to tell the interpreter that if any
@@ -191,28 +295,89 @@ 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 }}}
+.. L23
-%% 4 %% Run the script without using the -i option. Do you find any difference?
+.. R24
-{{{ continue from paused state }}}
+Pause here and try out the following exercise
+
+ Run the script without using the -i option. Do you find any difference?
+
+<Pause>
+
+.. L24
+
+.. L25
+
+::
+
+ %run -i /home/fossee/show_included.py
+
+.. R25
We see that it raises NameError saying that the name linspace is not found.
+.. L26
+
{{{ Show summary slide }}}
-This brings us to the end of the tutorial.
-we have looked at
+.. R26
+
+This brings us to the end of the tutorial.let's revise quickly what we have learnt today-
+
+ 1. to retreive the history using =%hist= command.
+ #. to view only a part of history by passing an argument to %hist.
+ #. to save the required lines of code in required order using %save.
+ #. to use %run -i command to run the saved script.
+
+.. L27
+
+{{Show self assessment questions slide}}
+
+.. R27
+
+Here are some self assessment questions for you to solve
+
+1. How do you retrieve the recent 5 commands
+
+ - ``%hist``
+ - ``%hist -5``
+ - ``%hist 5``
+ - ``%hist 5-10``
+
+
+2. How do you save the lines 2 3 4 5 7 9 10 11
+
+ - ``%save filepath 2-5 7 9-11``
+ - ``%save filepath 2-11``
+ - ``%save filepath``
+ - ``%save 2-5 7 9 10 11``
+
+
+3. What will the command ``%hist 5 10`` display.
+
+ - The recently typed commands from 5 to 10 inclusive of the history command
+ - The recently typed commands from 5 to 10 excluding the history command
+
+.. L28
+
+(solution of self assessment questions on slide)
+
+.. R28
+
+And the answers,
+
+1. In order to retrieve the recently typed 5 commands,we say ``%hist 5``.
+
+2. ``%save filepath 2-5 7 9-11`` is the correct option to the specified lines of codes.
- * 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
+3. ``%hist 5 10`` will display the recently typed commands from 5 to 10 inclusive of the history command.
-{{{ Show the "sponsored by FOSSEE" slide }}}
+.. L29
+{{a thank you slide}}
-This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India
+.. R29
Hope you have enjoyed and found it useful.
Thank You!
diff --git a/getting_started_with_ipython/slides.org b/getting_started_with_ipython/slides.org
index d729cca..3b6fd2b 100644
--- a/getting_started_with_ipython/slides.org
+++ b/getting_started_with_ipython/slides.org
@@ -18,7 +18,7 @@
#+LaTeX_HEADER: commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
#+LaTeX_HEADER: showstringspaces=false, keywordstyle=\color{blue}\bfseries}
-#+TITLE: Getting Started -- ~ipython~
+#+TITLE:
#+AUTHOR: FOSSEE
#+EMAIL:
#+DATE:
@@ -29,13 +29,28 @@
#+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
- + invoke the ~ipython~ interpreter
- + quit the ~ipython~ interpreter
- + navigate in the history of ~ipython~
- + use tab-completion
- + look-up documentation of functions
- + interrupt incomplete or incorrect commands
+*
+#+begin_latex
+\begin{center}
+\textcolor{blue}{Getting Started -- \texttt{ipython}}
+\end{center}
+\begin{center}
+\includegraphics[scale=0.25]{../images/iitb-logo.png}\\
+Developed by FOSSEE Team, IIT-Bombay. \\
+Funded by National Mission on Education through ICT
+
+MHRD, Govt. of India
+\end{center}
+#+end_latex
+
+* Objectives
+ At the end of this tutorial, you will be able to,
+ - invoke the ~ipython~ interpreter.
+ - quit the ~ipython~ interpreter.
+ - navigate in the history of ~ipython~.
+ - use tab-completion.
+ - look-up documentation of functions.
+ - interrupt incomplete or incorrect commands.
* Question 1
Type =ab= and hit tab to see what happens. Next, just type =a= and
hit tab to see what happens.
@@ -73,25 +88,50 @@
#+end_src
-
* Summary
- + invoking and quitting the ~ipython~ interpreter
- + navigating the history
- + using tab-completion to work faster
- + looking-up documentation using ~?~
- + sending keyboard interrupts using ~Ctrl-C~
+ In this tutorial, we have learnt to –
+ - invoke the ~ipython~ interpreter by typing ipython.
+ - quit the ~ipython~ interpreter by using ~Ctrl-d~.
+ - navigate in the history of ~ipython~ by using the arrow keys.
+ - use tab-completionto work faster.
+ - see the documentation of functions using question mark.
+ - interrupt using ~Ctrl-c~ when we make an error.
+* Evaluation
+ 1. Ipython is a programming similar to Python?
+ True or False
+
+ 2. Which key combination quits ``ipython``?
-* Thank you!
+ - Ctrl + C
+ - Ctrl + D
+ - Alt + C
+ - Alt + D
+
+ 3. Which character is used at the end of a command, in Ipython to
+ display the documentation.
+
+ - under score (_)
+ - question mark (?)
+ - exclamation mark (!)
+ - ampersand (&)
+* Solution
+ 1. False
+
+ 2. Ctrl + D
+
+ 3. question mark (?)
+
+* Acknowledgement
#+begin_latex
\begin{block}{}
\begin{center}
- This spoken tutorial has been produced by the
- \textcolor{blue}{FOSSEE} team, which is funded by the
+ \textcolor{blue}{\Large THANK YOU!}
\end{center}
+ \end{block}
+\begin{block}{}
\begin{center}
- \textcolor{blue}{National Mission on Education through \\
- Information \& Communication Technology \\
- MHRD, Govt. of India}.
+ For more Information, visit our website\\
+ \url{http://fossee.in/}
\end{center}
\end{block}
#+end_latex
diff --git a/using_plot_interactively/slides.org b/using_plot_interactively/slides.org
index 1716c83..73a638d 100644
--- a/using_plot_interactively/slides.org
+++ b/using_plot_interactively/slides.org
@@ -18,7 +18,7 @@
#+LaTeX_HEADER: commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
#+LaTeX_HEADER: showstringspaces=false, keywordstyle=\color{blue}\bfseries}
-#+TITLE: Using Plot Interactively
+#+TITLE:
#+AUTHOR: FOSSEE
#+EMAIL:
#+DATE:
@@ -29,6 +29,19 @@
#+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
+*
+#+begin_latex
+\begin{center}
+\textcolor{blue}{Using plot Interactively}
+\end{center}
+\begin{center}
+\includegraphics[scale=0.25]{../images/iitb-logo.png}\\
+Developed by FOSSEE Team, IIT-Bombay. \\
+Funded by National Mission on Education through ICT
+
+MHRD, Govt. of India
+\end{center}
+#+end_latex
* Objectives
At the end of this tutorial, you will be able to,
- Create simple plots of mathematical functions.