1. Home
  2. Docs
  3. Python-DataScience
  4. IPython and Shell
  5. Best comb: IPython+Notebook

Best comb: IPython+Notebook

Best combination for Python
IPython + Notebook

IPython: abbr. of Interactive Python, providing <Tab> for auto-completion and ‘?’ for signature (Function introduction)

======================

Magic functions of IPython

type ‘%magic’ to see introduction or ‘%lsmagic’ to list line and cell magic functions.

Common used (line) magic functions:
%paste : paste the latest content inside clipboard and auto-run, appropriate for function paste
%run : followed by directory of the .py script
%timeit : time the code in line (usually 3 runs to show robust result)

================

Input and Output

Input is stored as type ‘list’ and Output stored as type ‘dict’

In = []
Out = {}
‘_’ to ‘___’ infer last to third-to-last output
suppressing output with ‘;’ at the end of the line

========================

Errors & Debugging:

Errors prompt complexity option & Interactive Debugging

%xmode Plain : error Traceback information with minimal details
%xmode Context : intermedia details
%xmode Verbose : most details, any called function will be listed
According to the section and complexity of analyzed code, choose corresponding mode

%pdb : abbr. of python debugger
basic operations are:
up, down, help
quit : quit and end program
continue : quit and continue the program
next : go to next step
list : list files in current directory

====================

Profiling and Timing

Analyze time and space consuming of the program

%timeit : timing the script running time in python without cleaning the unused Python objects
%time : timing wholistic system time with unused Python objects cleaned.
%prun : profiling the time cosumption and rank of them

Following magic functions are not built-in for IPython:

%lprun : profile line by line;
pip install line_profiler
%load_ext line_profiler
%memit : (memory_profiler)
pip install memory profiler
%load_ext memory_profiler
%mprun : (memory_profiler)

===============

Was this article helpful to you? Yes 2 No

How can we help?