IPython creates and interactive environment within your shell application. IPython is widely used and few of its features are listed below:
- Tab completion
- History mechanism
- Inline editing
- Calls external Python scripts using the command
- Access to system commands
- Access to Python debugger and profiler
Below are few of the things you should now to get started using the IPython.
Start a new IPython session
To start a new session with IPython you type the following command:
(data_analysis) ddn_ro@Linux:~/env/data_analysis$ ipython3 Python 3.5.2 (default, Aug 18 2017, 17:48:00) Type 'copyright', 'credits' or 'license' for more information IPython 6.2.0 -- An enhanced Interactive Python. Type '?' for help. In :
You can quit the session by typing
quit() in the command line or by pressing
Saving an IPython session
You may want to save a session in order to be able to access it later. You can do that by running the command
%logstart in the IPython shell.
In : %logstart Activating auto-logging. Current session state plus future input saved. Filename : ipython_log.py Mode : rotate Output logging : False Raw input log : False Timestamping : False State : active In :
Logging can be switched off by running the command
%logoff in the IPython shell.
Execute a system shell command in IPython session
As I said, IPython can access system shell commands. It is done by prefixing the command with an exclamation mark (!).
In : !date Thu Sep 21 05:17:33 ICT 2017 In :
The command output can be stored as shown below:
In : todaydate = !date In : todaydate Out: ['Thu Sep 21 05:19:16 ICT 2017'] In :
Display history commands in IPython session
You can print in the shell a list of the previous commands using
%hist as shown below:
In : %hist %logstart !date todaydate = !date todaydate %hist In :
You can also search through history using the following command:
In : %hist -g date 1/3: !date 1/4: thedate = !date 1/5: thedate 1/8: %hist -g !date 2: !date 3: todaydate = !date 4: todaydate 6: %hist -g date In :