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. It's the same REPL that brands behind the Jupyter notebooks.
0:08 So if you're using Jupyter notebooks, then you will feel at home. Once you install IPython with pip, you can started by typing. Well,
0:16 I Python in your terminal, out of the box, We have syntax highlighting. We have automatic indentations.
0:27 So when we start writing a for loop and we press enter, IPython will automatically detect that we want to insert four spaces.
0:36 We get the tab completion. So, for example, when we want to import the function from some module,
0:40 we can just type some letters and keep pressing tab to find the function that we're looking for and one really nice thing is a dynamic object
0:49 Introspection. This is my single most favorite feature of IPython. You no longer need to search for documentation of a function or a module.
0:58 You just append the question mark to the name of the function, and IPython will show you the docstring of that object.
1:05 And if you want to see the complete source code, just use double question marks instead, it won't work in this case,
1:11 because chdir is a function that comes from CPython. But if you're using some external pip modules, then it will work. Let's try to,
1:19 import the function from IPython itself and see it. As you can see here we are importing some module from IPython genitals.
1:27 And then if we use double question mark, we can see the whole source code of this module.
1:34 Another cool thing is that you can run shell functions directly from IPython by prepending
1:39 your functions with the exclamation mark, so we can list the content of the current directory We can create a new file,
1:50 and we can even start vim from IPython. There are some helper functions called magic commands that you can use for some common things,
2:00 like measuring the execution time of some code, running a Python script without living the Python terminal and so on. One of them is, for example,
2:08 run that you can use to run, any Python file in the current I Python session So let's try to execute the file that we just created and it's working.
2:19 There are many more things that you can do if IPython. If you want to learn more,
2:23 I actually have a presentation on IPython that I gave at some conferences.
2:28 It's a 45 minute long, fast paced talk where I go through various features of
2:33 IPython. I will put a link to this presentation in the resource page of the course.


Talk Python's Mastodon Michael Kennedy's Mastodon