Ipython magic function

IPython的Magic函数

IPython提供了功能强大、内建的Magic函数,定义为: IPython中将任何第一个字母为%的行视为Magic函数的特殊调用,可以控制IPython,为其增加许多系统功能。

%lsmagic
%Exit %Pprint %Quit %alias %autocall %autoindent %automagic %bg %bookmark %cd %clear %color_info %colors %cpaste %debug %dhist %dirs %doctest_mode %ed %edit %env %exit %hist %history %logoff %logon %logstart %logstate %logstop %lsmagic %macro %magic %p %page %paste %pdb %pdef %pdoc %pfile %pinfo %popd %profile %prun %psearch %psource %pushd %pwd %pycat %quickref %quit %r %rehash %rehashx %rep %reset %run %runlog %save %sc %store %sx %system_verbose %time %timeit %unalias %upgrade %who %who_ls %whos %xmode

Automagic is ON, % prefix NOT needed for magic functions.
%cd mydir               #进入mydir目录

%save  fileX l-10       #save line 1 to 10 in fileX

有些带缩进的代码不能直接 ctrl+v , 要使用 %paste , %cpaste
%paste #承载一切文本粘贴。
%cpaste # ctrl +c as terminal

对象内省:在命令后面加 ? ,便可以输出帮助 ; ?? 查看该函数源代码

In [5]: %who ?
Type: Magic function
Base Class: <type 'instancemethod'>
String Form: method InteractiveShell.magic_who of <IPython.iplib.InteractiveShell object at 0xb77aa6cc>>
Namespace: IPython internal

运行python script.

%run test.py

搜索历史命令:
(向上键 ; Ctr - p) ; (向下键; Ctrl -N) ;
先输入前几个字符再搜索
Ctrl-R 部分增量搜索

记录输入输出:
%logstart #记录整个会话,包括之前的
%logstop
%logon
%logoff

别名工具 - 为shell command 自定义
%alias ll ls -l

你可能感兴趣的:(python)