What is IPython?

IPython provides a rich architecture for interactive computing with:

  • A powerful interactive shell.
  • A kernel for Jupyter.
  • Support for interactive data visualization and use of GUI toolkits.
  • Flexible, embeddable interpreters to load into your own projects.
  • Easy to use, high performance tools for parallel computing.

IPython is an interactive shell based on the Python interpreter. Compared with the basic Python shell, IPython provides more convenient interactive capabilities, such as Tab completion, easy to write func, and so on. And IPython also as the core of Jupyter, support parallel computing and so on. Can say: “used all say good ~” installation method

$pip install ipython
Copy the code

Boot method

$ipython
Copy the code

Stay Elegant (DRY rule)

Statistically, the most I typed in IPython at work was five lines:

In [1] :import json
In [2] :from pprint import pprint
In [3]: true = True
In [4]: false = False
In [5]: null = None
Copy the code

So every time I enter IPython, I have to type in this 5 lines of code first so that I can work on the actual problem later. It takes me 5 seconds (maybe a person with a fast hand can do it in 3 seconds). Anyway, it’s not DRY

Import from a PY file

The initial idea is to put all the common code in a py file, and then just import the file in IPython, like this:

Write an init.py file

import json
from pprint import pprint
true = True
false = False
null = None
Copy the code

In IPython you just import

In [1] :from init import *
In [2]: pprint(ture)
True
Copy the code

So instead of writing 5 lines, I’m going to write 1 line, so there’s not much difference between a fast hand and a slow hand

This is already very DRY. Is there a drier rule?

Have you heard of Startup in IPython

The DRY principle?? Wouldn’t that be zero rows?

Startup is a folder (its full path is ~/.ipython/profile_default/startup) that contains a README:

This is the IPython startup directory

.py and .ipy files in this directory will be run *prior* to any code or files specified
via the exec_lines or exec_files configurables whenever you load this profile.

Files will be run in lexicographical order, so you can control the execution order of files
with a prefix, e.g.::

    00-first.py
    50-middle.py
    99-last.ipy
Copy the code

In other words, if we put the init.py file we wrote earlier in this directory, it will be executed automatically when we start IPython

$mv init.py ~/.ipython/profile_default/startup
Copy the code

And then try again

In [1]: pprint(ture)
True
Copy the code

It’s work! This is pretty DRY, and EVERY time I use IPython I will save 5 seconds. Time management guru