IPython常用魔法方法

IPython常用魔法方法


複製代碼,使用–退出

In :%cpaste
Pasting code; enter '--' alone on the line to stop or use Ctrl-D.
:

查看歷史

In :hist -n 
1: my_macro    
2: hist -n    
3: a = 1    
4: b = 2    
5: c = 3
6: hist -n

保存文件

In :save test.py 3-5
File `test.py` exists. Overwrite (y/[N])?  y
The following commands were written to file `test.py`:
a = 1 
b = 2 
c = 3 

編輯文件,會使用默認的編輯器

In :edit test.sh
Editing... done. Executing edited code...

導入文件

In :load test.sh

In :!sh test.sh
to,121,112,223

In :cat test.sh
#!/bin/bash

array_name=("to","121","112","223")

for data in ${array_name[@]}  
do  
    echo "$data"
done 

測試執行時間

In :%timeit for _ in range(10000): 1

10000 loops, best of 3: 173 µs per loop

In :%timeit for _ in xrange(10000): 1
10000 loops, best of 3: 119 µs per loop

In :time range(10)
CPU times: user 3 µs, sys: 0 ns, total: 3 µs
Wall time: 3.81 µs
Out:[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

保持現場

In :logstart 1017.py
Activating auto-logging. Current session state plus future input saved.
Filename       : 1017.py
Mode           : backup
Output logging : False
Raw input log  : False
Timestamping   : False
State          : active

In :a = 1

In :b = 2

In :c =3 

In :c = 3

In :logoff
Switching logging OFF

root@zidy ~ >> ipython -i 1017.py  
Activating auto-logging. Current session state plus future input saved.
Filename       : 1017.py
Mode           : backup
Output logging : False
Raw input log  : False
Timestamping   : False
State          : active
Switching logging OFF

In :a
Out:1

In :b
Out:2

In :c
Out:3

標記路徑

In :%bookmark

UsageError: %bookmark: You must specify the bookmark name
In :%bookmark book /root/book/

In :cd book
/root/book

In :pwd
Out:u'/root/book'

常用命令

?     顯示方法參數,說明等
??   顯示方法的源碼
_      上一次的返回值

修改IPython提示符

ipython profile create
mv /root/.ipython/profile_default/ipython_config.py /root/.ipython/profile_default/ipython_config.py1
cp ipython_config.py /root/.ipython/profile_default/ipython_config.py

ipython_config.py需要下載,

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章