load .py file to ipython

%run: You've already been using this, but it's included here for completeness. %run module or %run module.py will execute the python code in the file module.py, and bring everything in that module's namespace into the current interactive namespace, which is different than if you had typed import module. NOTE: If both module and module.py exist, %run module will execute run the former (which may not be a python source file) rather than the latter.

help & ? & ??

? and ??: Typing ? after a name will give you information about the object attached to that name, e.g., if I type g.AddEdge?, where g is the graph I constructed above, then I see:

help: help(cv2.imread), just like cv2.imread?

who & whos

%who and %whos: These magic functions list objects, functions, etc. that have been added in the current namespace, as well as modules that have been imported. %who simply lists names of such objects, while %whos additionally lists type and data information (you might want to make your terminal window wide enough to capture all the output, since it doesn't do a great job with formatting the text), e.g.:

hist

%hist: This presents a list of the last several input command lines. (It presents ipython magic commands not as you typed them but as they were processed through the _ip.magic system; %hist -r will show the command lines exactly as you typed them.) Previous input commands are stored in the list In; e.g., In[37] will show the string associated with input line 37, and exec In[37] will actually (re)execute that line. Similarly, the output of each of the previous commands is stored in the Out variable, indexed by the line number. Finally, while typing input to a command line, hit <CONTROL>-P and ipython will present you with all previous command lines that began with the text you have typed (more efficient than paging through all previous commands with the UP arrow); repeatedly typing <CONTROL>-P cycles through this list.

macro

%macro: Assign a name to a set of input commands, so that they can be executed all together using the assigned name, e.g., if I start a session with the following 5 lines:

%run SmallWorldNetworks
g = MakeSmallWorldNetwork(100, 4, 0.1)
NetGraphics.DisplayCircleGraph(g)
distances = Networks.FindPathLengthsFromNode(g, 0)
print distances

then I can make a macro called runswn (short for RunSmallWorldNetworks) that executes everything from lines 1 through 5, inclusive:

%macro runswn 1-5

It is obviously of use to run %hist to find which specific line numbers need to be included in the macro. Line numbers need not be contiguous, e.g., %macro runswn 1-5 7 12-15 will assemble a macro from the specified disjoint set of command lines.

ipython

  • help

  • magic commands: %magic

  • system command aliase: %alias

  • dynamic object information: ?object or object? or ??object or object?? or %pdoc object

  • history: %hist, ctrl-p,ctrl-n,ctrl-r

  • system escape with !

  • ipython varible: _ih, _,__,___,_i,_ii,_iii,_dh

notebook

remote_user@remote_host$ ipython notebook --no-browser --port=8889 (out of date)
remote_user@remote_host$ jupyter notebook --no-browser --port=8889
local_user@local_host$ ssh -N -f -L localhost:8888:localhost:8889 remote_user@remote_host
local_user@local_host$ ps aux | grep localhost:8889
local_user 18418  0.0  0.0  41488   684 ?        Ss   17:27   0:00 ssh -N -f -L localhost:8888:localhost:8889 remote_user@remote_host
local_user 18424  0.0  0.0  11572   932 pts/6    S+   17:27   0:00 grep localhost:8889

local_user@local_host$ kill -15 18418

results matching ""

    No results matching ""