Difference between revisions of "Python-3.4.3/C2/Additional-features-of-IPython/English-timed"
PoojaMoolya (Talk | contribs) (Created page with "{| border=1 | <center>'''Time'''</center> | <center>'''Narration'''</center> |- | 00:01 | Hello friends and welcome to the Spoken Tutorial on''' Additional Features of IPytho...") |
Sandhya.np14 (Talk | contribs) |
||
(One intermediate revision by one other user not shown) | |||
Line 5: | Line 5: | ||
|- | |- | ||
| 00:01 | | 00:01 | ||
− | | Hello friends and welcome to the Spoken Tutorial on''' Additional Features of IPython'''. | + | | Hello friends and welcome to the '''Spoken Tutorial''' on''' Additional Features of IPython'''. |
|- | |- | ||
| 00:07 | | 00:07 | ||
− | | At the end of this tutorial, you will be able to | + | | At the end of this tutorial, you will be able to: retrieve your''' IPython''' '''history''', |
|- | |- | ||
| 00:14 | | 00:14 | ||
− | | | + | | view a part of the '''history''', |
|- | |- | ||
| 00:17 | | 00:17 | ||
− | | | + | | '''save''' a part of a '''history''' to a file, |
|- | |- | ||
| 00:21 | | 00:21 | ||
− | | | + | | '''run''' a script from within''' IPython'''. |
|- | |- | ||
| 00:25 | | 00:25 | ||
− | | To record this tutorial, I am using '''Ubuntu Linux 14.04''' operating system | + | | To record this tutorial, I am using: |
+ | '''Ubuntu Linux 14.04''' operating system, | ||
|- | |- | ||
| 00:32 | | 00:32 | ||
− | | '''Python 3.4.3''' | + | | '''Python 3.4.3''', |
'''IPython 5.1.0''' | '''IPython 5.1.0''' | ||
Line 37: | Line 38: | ||
| To practice this tutorial, you should know how to | | To practice this tutorial, you should know how to | ||
− | use | + | use '''plot'''s interactively and embellish a plot. |
|- | |- | ||
| 00:48 | | 00:48 | ||
− | | If not, see the pre-requisite Python tutorials on this website. | + | | If not, see the pre-requisite '''Python tutorials''' on this website. |
|- | |- | ||
Line 53: | Line 54: | ||
|- | |- | ||
| 01:07 | | 01:07 | ||
− | | Let us initialise the '''pylab package'''. Type '''percentage pylab '''and press''' Enter''' | + | | Let us initialise the '''pylab package'''. Type '''percentage pylab '''and press''' Enter'''. |
|- | |- | ||
| 01:14 | | 01:14 | ||
− | | To start plotting, type | + | | To start plotting, type: '''x is equal to linspace''' inside the brackets '''minus 2pi comma 2pi comma 100 ''' and press''' Enter.''' |
|- | |- | ||
| 01:31 | | 01:31 | ||
− | | Next type '''plot''' inside the ''' | + | | Next, type: '''plot''' inside the brackets '''x comma xsin(x) '''and press''' Enter'''. |
|- | |- | ||
| 01:42 | | 01:42 | ||
− | | We got an error | + | | We got an '''error''' saying '''"xsin is not defined".''' |
− | This is because '''xsin(x) '''is actually '''x '''multiplied by '''sin(x)''' | + | This is because '''xsin(x) '''is actually '''x '''multiplied by '''sin(x)'''. |
|- | |- | ||
| 01:54 | | 01:54 | ||
− | | Here, multiplication sign is missing. So let us now type | + | | Here, the multiplication sign is missing. So, let us now type: |
− | '''plot''' inside the ''' | + | '''plot''' inside the brackets '''x comma x multiplied by sin(x)''' and press '''Enter'''. |
|- | |- | ||
|02:13 | |02:13 | ||
− | | Next let us add '''title''' and the '''labels''' for both '''x''' and '''y axes'''. | + | | Next, let us add '''title''' and the '''labels''' for both '''x''' and '''y axes'''. |
|- | |- | ||
| 02:19 | | 02:19 | ||
− | | Type '''xlabel''' inside the | + | | Type: '''xlabel''' inside the brackets inside inverted commas inside dollar sign '''x ''' and press '''Enter.''' |
|- | |- | ||
| 02:31 | | 02:31 | ||
− | | '''ylabel''' inside the | + | | '''ylabel''' inside the brackets inside inverted commas inside dollar sign '''f(x) '''. |
|- | |- | ||
| 02:43 | | 02:43 | ||
− | | ''' | + | | '''title''' inside the brackets inside inverted commas inside dollar sign '''x and xsin(x). ''' |
|- | |- | ||
Line 97: | Line 98: | ||
|- | |- | ||
|03:01 | |03:01 | ||
− | | The '''history''' of typed ''' | + | | The '''history''' of typed '''command'''s can be retrieved by the ''' percentage history''' command. |
|- | |- | ||
| 03:07 | | 03:07 | ||
− | | Type '''percentage history''' and press''' Enter'''. | + | | Type: '''percentage history''' and press''' Enter'''. |
|- | |- | ||
Line 109: | Line 110: | ||
|- | |- | ||
| 03:20 | | 03:20 | ||
− | | Whatever we executed in the '''terminal''' is stored as history. | + | | Whatever we executed in the '''terminal''', is stored as history. |
|- | |- | ||
| 03:25 | | 03:25 | ||
− | | If we want to see what was the fifth '''command''', pass 5 as an '''argument''' to''' percentage history | + | | If we want to see what was the fifth '''command''', pass 5 as an '''argument''' to''' percentage history ''' command. |
|- | |- | ||
| 03:33 | | 03:33 | ||
− | | Type '''percentage history space 5 '''and press''' Enter'''. | + | | Type: '''percentage history space 5 '''and press''' Enter'''. |
− | This displays the fifth | + | This displays the fifth command which we typed. |
|- | |- | ||
| 03:43 | | 03:43 | ||
− | | Now pause the video here | + | | Now, pause the video here and try out the following exercise and resume the video. |
|- | |- | ||
| 03:49 | | 03:49 | ||
− | | Find out how to list the recent | + | | Find out how to list the recent commands between 5 and 10. |
|- | |- | ||
| 03:55 | | 03:55 | ||
− | | Switch back to '''terminal'''. | + | | Switch back to the '''terminal'''. |
|- | |- | ||
Line 139: | Line 140: | ||
|- | |- | ||
| 04:00 | | 04:00 | ||
− | | Type '''clf()''' and | + | | Type '''clf()''' and press '''Enter'''. |
− | Type '''percentage history question mark ''' | + | Type: '''percentage history question mark ''' |
|- | |- | ||
| 04:08 | | 04:08 | ||
− | | Read through the information of''' percentage history | + | | Read through the information of''' percentage history''' command. |
|- | |- | ||
| 04:13 | | 04:13 | ||
− | | We can see, '''percentage history hyphen n 4 hyphen 6''' displays the | + | | We can see, '''percentage history hyphen n 4 hyphen 6''' displays the commands from 4 to 6. |
|- | |- | ||
| 04:24 | | 04:24 | ||
− | | Here '''hyphen n '''is an optional '''argument''' which prints the line numbers. | + | | Here, '''hyphen n '''is an optional '''argument''' which prints the line numbers. |
− | Type '''q '''to quit the documentation | + | Type '''q '''to quit the documentation. |
|- | |- | ||
| 04:37 | | 04:37 | ||
− | | Now type '''percentage history space 5 hyphen 10''' and press''' Enter.''' | + | | Now, type: '''percentage history space 5 hyphen 10''' and press''' Enter.''' |
|- | |- | ||
| 04:46 | | 04:46 | ||
− | | To save the '''history''', we use the '''percentage save | + | | To '''save''' the '''history''', we use the '''percentage save''' command. |
|- | |- | ||
| 04:51 | | 04:51 | ||
− | | Before we do that, let us first look at the '''history''' and identify which lines of code we require. | + | | Before we do that, let us first look at the '''history''' and identify which lines of '''code''' we require. |
|- | |- | ||
Line 185: | Line 186: | ||
|- | |- | ||
| 05:13 | | 05:13 | ||
− | | The | + | | The commands from fourth to seventh are required. |
|- | |- | ||
| 05:16 | | 05:16 | ||
− | | So we need the second '''command''' and then the fourth to seventh '''commands''' for our program. | + | | So, we need the second '''command''' and then the fourth to seventh '''commands''' for our program. |
|- | |- | ||
| 05:22 | | 05:22 | ||
− | | Let us save it in the present working directory. Hence the syntax will be | + | | Let us '''save''' it in the present '''working directory'''. Hence the syntax will be- |
− | '''percentage save space plot underscore script.py space 2 space 4 hyphen 7''' and press''' Enter''' | + | '''percentage save space plot underscore script.py space 2 space 4 hyphen 7''' and press''' Enter'''. |
|- | |- | ||
| 05:47 | | 05:47 | ||
− | | The first '''argument''' in '''percentage save | + | | The first '''argument''' in '''percentage save''' command is the name of the file in which the commands are saved. |
|- | |- | ||
Line 211: | Line 212: | ||
|- | |- | ||
| 06:13 | | 06:13 | ||
− | | Let us learn how to run the file as a '''python script.''' | + | | Let us learn how to '''run''' the file as a '''python script.''' |
− | We use the ''' | + | We use the command '''percentage run''' to do this. |
|- | |- | ||
| 06:22 | | 06:22 | ||
− | | Type '''percentage run space hyphen i space plot underscore script.py''' and press''' Enter.''' | + | | Type: '''percentage run space hyphen i space plot underscore script.py''' and press''' Enter.''' |
|- | |- | ||
| 06:38 | | 06:38 | ||
− | | | + | |Here, '''hyphen i''' parameter '''run'''s the '''code''' written in a '''text editor'''. |
− | Here, '''hyphen i''' parameter | + | |
The code is run within the current '''ipython''' session. | The code is run within the current '''ipython''' session. | ||
Line 240: | Line 240: | ||
|- | |- | ||
| 07:07 | | 07:07 | ||
− | | To view the | + | | To view the plot, type''' show()''' on your '''terminal''' and press '''Enter.''' |
|- | |- | ||
| 07:15 | | 07:15 | ||
− | | Pause the video here | + | | Pause the video here and try out the following exercise and resume. |
|- | |- | ||
Line 252: | Line 252: | ||
|- | |- | ||
| 07:30 | | 07:30 | ||
− | | Run the '''script''' to produce the '''plot''' and display the same. | + | | '''Run''' the '''script''' to produce the '''plot''' and display the same. |
|- | |- | ||
Line 258: | Line 258: | ||
| Let us look at the solution. | | Let us look at the solution. | ||
− | We first look at the '''history''' using''' | + | We first look at the '''history''' using the''' percentage history hyphen n''' command. |
|- | |- | ||
| 07:44 | | 07:44 | ||
− | | Type '''percentage history space hyphen n''' and press''' Enter.''' | + | | Type: '''percentage history space hyphen n''' and press''' Enter.''' |
|- | |- | ||
| 07:54 | | 07:54 | ||
− | | Let us clear the plot window | + | | Let us clear the plot window. |
− | Type '''clf()''' and press '''Enter''' | + | Type '''clf()''' and press '''Enter'''. |
|- | |- | ||
| 08:01 | | 08:01 | ||
− | | Now let us save the '''script''' using the '''command''' '''percentage save''' | + | | Now, let us save the '''script''' using the '''command''' '''percentage save'''. |
|- | |- | ||
| 08:07 | | 08:07 | ||
− | | We need lines 2, then 4 to 7 and 16 | + | | We need the lines 2, then 4 to 7 and 16. |
|- | |- | ||
| 08:20 | | 08:20 | ||
− | | Type '''percentage save space show underscore included.py space 2 space 4 hyphen 7 space 16''' and press''' Enter''' | + | | Type: '''percentage save space show underscore included.py space 2 space 4 hyphen 7 space 16''' and press''' Enter'''. |
|- | |- | ||
| 08:41 | | 08:41 | ||
− | | To run the script type | + | | To '''run''' the script, type: |
− | '''percentage run space hyphen i space show underscore included.py''' | + | '''percentage run space hyphen i space show underscore included.py''' and press''' Enter'''. |
− | + | ||
− | + | ||
|- | |- | ||
Line 296: | Line 294: | ||
|- | |- | ||
| 09:01 | | 09:01 | ||
− | | Go to the previous | + | | Go to the previous command. |
− | + | Modify it by removing ‘'''hyphen i’''' in the command to '''percentage run space show included.py''' and Press '''Enter'''. | |
− | + | ||
|- | |- | ||
| 09:16 | | 09:16 | ||
− | | We see that it raises a '''NameError''' saying that the | + | | We see that it raises a '''NameError''' saying that the '''name 'linspace' is not defined'''. |
− | This happens because we did not run the script interactively. | + | This happens because we did not '''run''' the script interactively. |
|- | |- | ||
| 09:30 | | 09:30 | ||
− | | This brings us to the end of this tutorial. In this tutorial,we have learnt to | + | | This brings us to the end of this tutorial. In this tutorial, we have learnt to: |
− | + | retrieve the '''history''' using '''percentage history''' command, | |
|- | |- | ||
| 09:41 | | 09:41 | ||
− | | | + | | view only a part of '''history''' by passing argument to''' percentage history''' command, |
|- | |- | ||
| 09:48 | | 09:48 | ||
− | | | + | | save the required lines of code, in required order using '''percentage save''' command. |
|- | |- | ||
Line 326: | Line 323: | ||
|- | |- | ||
| 10:04 | | 10:04 | ||
− | | Here are some self assessment questions | + | | Here are some self assessment questions. |
|- | |- | ||
Line 344: | Line 341: | ||
| '''percentage save filename''' | | '''percentage save filename''' | ||
− | '''percentage save 2 hyphen 5 7 9 | + | '''percentage save 2 hyphen 5 7 9 10 and 11''' |
|- | |- | ||
| 10:40 | | 10:40 | ||
− | | Which is the command to run the script? | + | | Which is the command to '''run''' the script? |
'''Percentage execute the script name''' | '''Percentage execute the script name''' | ||
Line 364: | Line 361: | ||
|- | |- | ||
| 10:58 | | 10:58 | ||
− | | And the solutions are | + | | And the solutions are- |
− | To save the commands 2 3 4 5 7 9 10 11, we issue the ''' | + | To save the commands 2 3 4 5 7 9 10 and 11, we issue the command '''percentage save filename 2 hyphen 5 space 7 space 9 hyphen 11'''. |
|- | |- | ||
| 11:18 | | 11:18 | ||
− | | To run the script we use '''percentage run space hyphen i space scriptname''' | + | | To run the script, we use '''percentage run space hyphen i space scriptname'''. |
|- | |- | ||
Line 378: | Line 375: | ||
|- | |- | ||
| 11:32 | | 11:32 | ||
− | | Please post your general queries on Python in this forum. | + | | Please post your general queries on '''Python''' in this forum. |
|- | |- | ||
| 11:37 | | 11:37 | ||
− | | The FOSSEE team coordinates the TBC project. | + | | The '''FOSSEE''' team coordinates the '''TBC project'''. |
|- | |- | ||
| 11:41 | | 11:41 | ||
− | | Spoken Tutorial | + | | '''Spoken Tutorial''' project is funded by '''NMEICT, MHRD''', Govt. of India. |
For more details, visit this website. | For more details, visit this website. | ||
Line 392: | Line 389: | ||
|- | |- | ||
|11:52 | |11:52 | ||
− | | This is Usha from IIT Bombay (or FOSSEE, if you wish) signing off. | + | | This is Usha from '''IIT Bombay''' (or FOSSEE, if you wish), signing off. |
|} | |} |
Latest revision as of 22:19, 13 June 2019
|
|
00:01 | Hello friends and welcome to the Spoken Tutorial on Additional Features of IPython. |
00:07 | At the end of this tutorial, you will be able to: retrieve your IPython history, |
00:14 | view a part of the history, |
00:17 | save a part of a history to a file, |
00:21 | run a script from within IPython. |
00:25 | To record this tutorial, I am using:
Ubuntu Linux 14.04 operating system, |
00:32 | Python 3.4.3,
IPython 5.1.0 |
00:38 | To practice this tutorial, you should know how to
use plots interactively and embellish a plot. |
00:48 | If not, see the pre-requisite Python tutorials on this website. |
00:54 | Let us now open the Terminal by pressing Ctrl+Alt+T keys simultaneously. |
01:01 | Now, type ipython3 and press Enter. |
01:07 | Let us initialise the pylab package. Type percentage pylab and press Enter. |
01:14 | To start plotting, type: x is equal to linspace inside the brackets minus 2pi comma 2pi comma 100 and press Enter. |
01:31 | Next, type: plot inside the brackets x comma xsin(x) and press Enter. |
01:42 | We got an error saying "xsin is not defined".
This is because xsin(x) is actually x multiplied by sin(x). |
01:54 | Here, the multiplication sign is missing. So, let us now type:
plot inside the brackets x comma x multiplied by sin(x) and press Enter. |
02:13 | Next, let us add title and the labels for both x and y axes. |
02:19 | Type: xlabel inside the brackets inside inverted commas inside dollar sign x and press Enter. |
02:31 | ylabel inside the brackets inside inverted commas inside dollar sign f(x) . |
02:43 | title inside the brackets inside inverted commas inside dollar sign x and xsin(x). |
02:57 | We can now see the labelled plot. |
03:01 | The history of typed commands can be retrieved by the percentage history command. |
03:07 | Type: percentage history and press Enter. |
03:13 | percentage history itself is a command and is displayed as the most recent command. |
03:20 | Whatever we executed in the terminal, is stored as history. |
03:25 | If we want to see what was the fifth command, pass 5 as an argument to percentage history command. |
03:33 | Type: percentage history space 5 and press Enter.
This displays the fifth command which we typed. |
03:43 | Now, pause the video here and try out the following exercise and resume the video. |
03:49 | Find out how to list the recent commands between 5 and 10. |
03:55 | Switch back to the terminal. |
03:58 | Let us look at the solution. |
04:00 | Type clf() and press Enter.
Type: percentage history question mark |
04:08 | Read through the information of percentage history command. |
04:13 | We can see, percentage history hyphen n 4 hyphen 6 displays the commands from 4 to 6. |
04:24 | Here, hyphen n is an optional argument which prints the line numbers.
Type q to quit the documentation. |
04:37 | Now, type: percentage history space 5 hyphen 10 and press Enter. |
04:46 | To save the history, we use the percentage save command. |
04:51 | Before we do that, let us first look at the history and identify which lines of code we require. |
04:58 | Type percentage history and press Enter. |
05:03 | The second command is linspace.
But the third command is a command that gave us an error. |
05:10 | Hence we do not need it. |
05:13 | The commands from fourth to seventh are required. |
05:16 | So, we need the second command and then the fourth to seventh commands for our program. |
05:22 | Let us save it in the present working directory. Hence the syntax will be-
percentage save space plot underscore script.py space 2 space 4 hyphen 7 and press Enter. |
05:47 | The first argument in percentage save command is the name of the file in which the commands are saved. |
05:56 | The second argument gives the numbers of the commands that are being saved separated by spaces. |
06:04 | Let us now open the file plot underscore script.py and see the contents. |
06:13 | Let us learn how to run the file as a python script.
We use the command percentage run to do this. |
06:22 | Type: percentage run space hyphen i space plot underscore script.py and press Enter. |
06:38 | Here, hyphen i parameter runs the code written in a text editor.
The code is run within the current ipython session. |
06:50 | It uses the variables defined interactively in the ipython session. |
06:56 | The script runs but we do not see the plot. |
07:01 | This is because when we are running a script, we are not in the interactive mode. |
07:07 | To view the plot, type show() on your terminal and press Enter. |
07:15 | Pause the video here and try out the following exercise and resume. |
07:21 | Use percentage history and percentage save to create a script that has the function show() in it. |
07:30 | Run the script to produce the plot and display the same. |
07:35 | Let us look at the solution.
We first look at the history using the percentage history hyphen n command. |
07:44 | Type: percentage history space hyphen n and press Enter. |
07:54 | Let us clear the plot window.
Type clf() and press Enter. |
08:01 | Now, let us save the script using the command percentage save. |
08:07 | We need the lines 2, then 4 to 7 and 16. |
08:20 | Type: percentage save space show underscore included.py space 2 space 4 hyphen 7 space 16 and press Enter. |
08:41 | To run the script, type:
percentage run space hyphen i space show underscore included.py and press Enter. |
08:57 | We get the desired plot. |
09:01 | Go to the previous command.
Modify it by removing ‘hyphen i’ in the command to percentage run space show included.py and Press Enter. |
09:16 | We see that it raises a NameError saying that the name 'linspace' is not defined.
This happens because we did not run the script interactively. |
09:30 | This brings us to the end of this tutorial. In this tutorial, we have learnt to:
retrieve the history using percentage history command, |
09:41 | view only a part of history by passing argument to percentage history command, |
09:48 | save the required lines of code, in required order using percentage save command. |
09:55 | Use 'percentage run space hyphen i' command to run a saved script. |
10:04 | Here are some self assessment questions. |
10:08 | How do you save the command lines 2 3 4 5 7 9 10 and 11? |
10:17 | percentage save filename 2-5 7 9 hyphen 11 |
10:25 | percentage save filename 2 hyphen 11 |
10:30 | percentage save filename
percentage save 2 hyphen 5 7 9 10 and 11 |
10:40 | Which is the command to run the script?
Percentage execute the script name |
10:46 | percentage run hyphen i script name
percentage run script name |
10:53 | percentage execute hyphen i script name |
10:58 | And the solutions are-
To save the commands 2 3 4 5 7 9 10 and 11, we issue the command percentage save filename 2 hyphen 5 space 7 space 9 hyphen 11. |
11:18 | To run the script, we use percentage run space hyphen i space scriptname. |
11:27 | Please post your timed queries in this forum. |
11:32 | Please post your general queries on Python in this forum. |
11:37 | The FOSSEE team coordinates the TBC project. |
11:41 | Spoken Tutorial project is funded by NMEICT, MHRD, Govt. of India.
For more details, visit this website. |
11:52 | This is Usha from IIT Bombay (or FOSSEE, if you wish), signing off. |