IPython常用魔法方法

来源:互联网 发布:淘宝招工 编辑:程序博客网 时间:2024/05/17 01:18

IPython常用魔法方法


复制代码,使用–退出

In :%cpastePasting 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 = 36: hist -n

保存文件

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

编辑文件,会使用默认的编辑器

In :edit test.shEditing... done. Executing edited code...

导入文件

In :load test.shIn :!sh test.shto,121,112,223In :cat test.sh#!/bin/basharray_name=("to","121","112","223")for data in ${array_name[@]}  do      echo "$data"done 

测试执行时间

In :%timeit for _ in range(10000): 110000 loops, best of 3: 173 µs per loopIn :%timeit for _ in xrange(10000): 110000 loops, best of 3: 119 µs per loopIn :time range(10)CPU times: user 3 µs, sys: 0 ns, total: 3 µsWall time: 3.81 µsOut:[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

保持现场

In :logstart 1017.pyActivating auto-logging. Current session state plus future input saved.Filename       : 1017.pyMode           : backupOutput logging : FalseRaw input log  : FalseTimestamping   : FalseState          : activeIn :a = 1In :b = 2In :c =3 In :c = 3In :logoffSwitching logging OFFroot@zidy ~ >> ipython -i 1017.py  Activating auto-logging. Current session state plus future input saved.Filename       : 1017.pyMode           : backupOutput logging : FalseRaw input log  : FalseTimestamping   : FalseState          : activeSwitching logging OFFIn :aOut:1In :bOut:2In :cOut:3

标记路径

In :%bookmarkUsageError: %bookmark: You must specify the bookmark nameIn :%bookmark book /root/book/In :cd book/root/bookIn :pwdOut:u'/root/book'

常用命令

?     显示方法参数,说明等??   显示方法的源码_      上一次的返回值

修改IPython提示符

ipython profile createmv /root/.ipython/profile_default/ipython_config.py /root/.ipython/profile_default/ipython_config.py1cp ipython_config.py /root/.ipython/profile_default/ipython_config.py

ipython_config.py需要下载,