Modern Python Projects Transcripts
Chapter: Writing code
Lecture: IPython

Login or purchase this course to watch this video and the rest of the course contents.
0:00 IPython is probably the most popular REPL for Python.
0:03 It's the same REPL that brands behind the Jupiter notebooks.
0:07 So if you're using Jupyter notebooks,
0:09 then you will feel at home.
0:10 Once you install IPython with pip,
0:12 you can started by typing. Well,
0:15 I python in your terminal, out of the box,
0:22 We have syntax highlighting. We have automatic indentations.
0:26 So when we start writing a for loop and we press enter,
0:30 IPython will automatically detect that we want to insert four spaces.
0:35 We get the tab completion. So,
0:37 for example, when we want to import the function from some module,
0:39 we can just type some letters and keep pressing tab to find the function that we're
0:44 looking for and one really nice thing is a dynamic object
0:48 Introspection. This is my single most favorite feature of IPython.
0:53 You no longer need to search for documentation of a function or a module.
0:57 You just append the question mark to the name of the function,
1:00 and IPython will show you the docstring of that object.
1:04 And if you want to see the complete source code,
1:06 just use double question marks instead,
1:09 it won't work in this case,
1:10 because chdir is a function that comes from C Python.
1:13 But if you're using some external pip modules,
1:15 then it will work. Let's try to,
1:18 import the function from Ipython itself and see it.
1:21 As you can see here we are importing some module from Ipython genitals.
1:26 And then if we use double question mark,
1:29 we can see the whole source code of this module.
1:33 Another cool thing is that you can run shell functions directly from Ipython by prepending
1:38 your functions with the exclamation mark, so we can list the content of the current directory
1:43 We can create a new file,
1:49 and we can even start vim from Ipython.
1:55 There are some helper functions called magic commands that you can use for some common things,
1:59 like measuring the execution time of some code,
2:02 running a python script without living the python terminal and so on.
2:06 One of them is, for example,
2:07 run that you can use to run, any python file in the current I Python session
2:11 So let's try to execute the file that we just created and it's working.
2:18 There are many more things that you can do if IPython.
2:21 If you want to learn more,
2:22 I actually have a presentation on IPython that I gave at some conferences.
2:27 It's a 45 minute long, fast paced talk where I go through various features of
2:32 IPython. I will put a link to this presentation in the resource page of the course.