IPython Quick Reference Card

IPython QuickRef:

IPython -- An enhanced Interactive Python - Quick Reference Card
================================================================

obj?, obj??      : Get help, or more help for object (also works as ?obj, ??obj).
?foo.*abc*       : List names in 'foo' containing 'abc' in them.
%magic           : Information about IPython's 'magic' % functions.

Magic functions are prefixed by % or %%, and typically take their arguments
without parentheses, quotes or even commas for convenience.  Line magics take a
single % and cell magics are prefixed with two %%.

Example magic function calls:

%alias d ls -F   : 'd' is now an alias for 'ls -F'
alias d ls -F    : Works if 'alias' not a python name
alist = %alias   : Get list of aliases to 'alist'
cd /usr/share    : Obvious. cd -<tab> to choose from visited dirs.
%cd??            : See help AND source for magic %cd
%timeit x=10     : time the 'x=10' statement with high precision.
%%timeit x=2**100
x**100           : time 'x*100' with a setup of 'x=2**100'; setup code is not
                   counted.  This is an example of a cell magic.

System commands:

!cp a.txt b/     : System command escape, calls os.system()
cp a.txt b/      : after %rehashx, most system commands work without !
cp ${f}.txt $bar : Variable expansion in magics and system commands
files = !ls /usr : Capture sytem command output
files.s, files.l, files.n: "a b c", ['a','b','c'], 'a\nb\nc'

History:

_i, _ii, _iii    : Previous, next previous, next next previous input
_i4, _ih[2:5]    : Input history line 4, lines 2-4
exec _i81        : Execute input history line #81 again
%rep 81          : Edit input history line #81
_, __, ___       : previous, next previous, next next previous output
_dh              : Directory history
_oh              : Output history
%hist            : Command history. '%hist -g foo' search history for 'foo'

Autocall:

f 1,2            : f(1,2)  # Off by default, enable with %autocall magic.
/f 1,2           : f(1,2) (forced autoparen)
,f 1 2           : f("1","2")
;f 1 2           : f("1 2")

Remember: TAB completion works in many contexts, not just file names
or python names.

The following magic functions are currently available:

%alias:
    Define an alias for a system command.
%alias_magic:
    %alias_magic [-l] [-c] name target
%autocall:
    Make functions callable without having to type parentheses.
%automagic:
    Make magic functions callable without having to type the initial %.
%autosave:
    Set the autosave interval in the notebook (in seconds).
%bookmark:
    Manage IPython's bookmark system.
%cd:
    Change the current working directory.
%clear:
    Clear the terminal.
%cls:
    Clear the terminal.
%colors:
    Switch color scheme for prompts, info system and exception handlers.
%config:
    configure IPython
%connect_info:
    Print information for connecting other clients to this kernel
%debug:
    %debug [--breakpoint FILE:LINE] [statement [statement ...]]
%dhist:
    Print your history of visited directories.
%dirs:
    Return the current directory stack.
%doctest_mode:
    Toggle doctest mode on and off.
%ed:
    Alias for `%edit`.
%edit:
    Bring up an editor and execute the resulting code.
%env:
    List environment variables.
%gui:
    Enable or disable IPython GUI event loop integration.
%guiref:
    Show a basic reference about the GUI Console.
%hist:
    Alias for `%history`.
%history:
    %history [-n] [-o] [-p] [-t] [-f FILENAME] [-g [PATTERN [PATTERN ...]]]
%install_default_config:
    %install_default_config has been deprecated.
%install_ext:
    Download and install an extension from a URL, e.g.::
%install_profiles:
    %install_profiles has been deprecated.
%killbgscripts:
    Kill all BG processes started by %%script and its family.
%less:
    Show a file through the pager.
%load:
    Load code into the current frontend.
%load_ext:
    Load an IPython extension by its module name.
%loadpy:
    Alias of `%load`
%logoff:
    Temporarily stop logging.
%logon:
    Restart logging.
%logstart:
    Start logging anywhere in a session.
%logstate:
    Print the status of the logging system.
%logstop:
    Fully stop logging and close log file.
%lsmagic:
    List currently available magic functions.
%macro:
    Define a macro for future re-execution. It accepts ranges of history,
%magic:
    Print information about the magic function system.
%matplotlib:
    %matplotlib [gui]
%more:
    Show a file through the pager.
%notebook:
    %notebook [-e] [-f FORMAT] filename
%page:
    Pretty print the object and display it through a pager.
%pastebin:
    Upload code to Github's Gist paste bin, returning the URL.
%pdb:
    Control the automatic calling of the pdb interactive debugger.
%pdef:
    Print the call signature for any callable object.
%pdoc:
    Print the docstring for an object.
%pfile:
    Print (or run through pager) the file where an object is defined.
%pinfo:
    Provide detailed information about an object.
%pinfo2:
    Provide extra detailed information about an object.
%popd:
    Change to directory popped off the top of the stack.
%pprint:
    Toggle pretty printing on/off.
%precision:
    Set floating point precision for pretty printing.
%profile:
    Print your currently active IPython profile.
%prun:
    Run a statement through the python code profiler.
%psearch:
    Search for object in namespaces by wildcard.
%psource:
    Print (or run through pager) the source code for an object.
%pushd:
    Place the current dir on stack and change directory.
%pwd:
    Return the current working directory path.
%pycat:
    Show a syntax-highlighted file through a pager.
%pylab:
    %pylab [--no-import-all] [gui]
%qtconsole:
    Open a qtconsole connected to this kernel.
%quickref:
    Show a quick reference sheet 
%recall:
    Repeat a command, or get command to input line for editing.
%rehashx:
    Update the alias table with all executable files in $PATH.
%reload_ext:
    Reload an IPython extension by its module name.
%rep:
    Alias for `%recall`.
%rerun:
    Re-run previous input
%reset:
    Resets the namespace by removing all names defined by the user, if
%reset_selective:
    Resets the namespace by removing names defined by the user.
%run:
    Run the named file inside IPython as a program.
%save:
    Save a set of lines or a macro to a given filename.
%sc:
    Shell capture - run shell command and capture output (DEPRECATED use !).
%store:
    Lightweight persistence for python variables.
%sx:
    Shell execute - run shell command and capture output (!! is short-hand).
%system:
    Shell execute - run shell command and capture output (!! is short-hand).
%tb:
    Print the last traceback with the currently active exception mode.
%time:
    Time execution of a Python statement or expression.
%timeit:
    Time execution of a Python statement or expression
%unalias:
    Remove an alias
%unload_ext:
    Unload an IPython extension by its module name.
%who:
    Print all interactive variables, with some minimal formatting.
%who_ls:
    Return a sorted list of all interactive variables.
%whos:
    Like %who, but gives some extra information about each variable.
%xdel:
    Delete a variable, trying to clear it from anywhere that
%xmode:
    Switch modes for the exception handlers.
%%!:
    Shell execute - run shell command and capture output (!! is short-hand).
%%HTML:
    Alias for `%%html`.
%%SVG:
    Alias for `%%svg`.
%%bash:
    %%bash script magic
%%capture:
    %capture [--no-stderr] [--no-stdout] [output]
%%cmd:
    %%cmd script magic
%%debug:
    %debug [--breakpoint FILE:LINE] [statement [statement ...]]
%%file:
    Alias for `%%writefile`.
%%html:
    Render the cell as a block of HTML
%%javascript:
    Run the cell block of Javascript code
%%latex:
    Render the cell as a block of latex
%%perl:
    %%perl script magic
%%powershell:
    %%powershell script magic
%%prun:
    Run a statement through the python code profiler.
%%pypy:
    %%pypy script magic
%%python:
    %%python script magic
%%python3:
    %%python3 script magic
%%ruby:
    %%ruby script magic
%%script:
    %shebang [--proc PROC] [--bg] [--err ERR] [--out OUT]
%%sh:
    %%sh script magic
%%svg:
    Render the cell as an SVG literal
%%sx:
    Shell execute - run shell command and capture output (!! is short-hand).
%%system:
    Shell execute - run shell command and capture output (!! is short-hand).
%%time:
    Time execution of a Python statement or expression.
%%timeit:
    Time execution of a Python statement or expression
%%writefile:
    %writefile [-a] filename


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Python 2.4 Quick Reference Card ©2005-2007 — Laurent Pointal — License CC [by nc sa] CARD CONTENT Environment Variables........................1 Command-line Options.......................1 Files Extensions..................................1 Language Keywords............................1 Builtins................................................1 Types....................................................1 Functions..............................................1 Statements.........................................1 Blocks....................................................1 Assignment Shortcuts...........................1 Console & Interactive Input/Output....2 Objects, Names and Namespaces......2 Identifiers..............................................2 Objects and Names, Reference Counting...............................................2 Mutable/Immutable Objects..................2 Namespaces.........................................2 Constants, Enumerations......................2 Flow Control........................................2 Condition...............................................2 Loop......................................................2 Functions/methods exit.........................2 Exceptions............................................2 Iterable Protocol....................................2 Interpretation / Execution...................2 Functions Definitions & Usage............2 Parameters / Return value....................2 Lambda functions.................................2 Callable Objects....................................2 Calling Functions...................................3 Functions Control..................................3 Decorators............................................3 Types/Classes & Objects.....................3 Class Definition.....................................3 Object Creation.....................................3 Classes & Objects Relations..................3 Attributes Manipulation.........................3 Special Methods....................................3 Descriptors protocol..............................3 Copying Objects....................................3 Introspection.........................................3 Modules and Packages........................3 Source encodings..................................3 Special Attributes..................................3 Main Execution / Script Parameters....4 Operators............................................4 Priority..................................................4 Arithmetic Operators............................4 Comparison Operators..........................4 Operators as Functions.........................4 Booleans.............................................4 Numbers.............................................4 Operators..............................................4 Functions..............................................4 Bit Level Operations...........................5 Operators..............................................5 Strings................................................5 Escape sequences.................................5 Unicode strings.....................................5 Methods and Functions.........................5 Formating..............................................6 Constants..............................................6 Regular Expressions..............................6 Localization...........................................7 Multilingual Support..............................7 Containers..........................................8 Operations on Containers.....................8 Copying Containers...............................8 Overriding Containers Operations........8 Sequences..........................................8 Lists & Tuples........................................8 Operations on Sequences.....................8 Indexing................................................8 Operations on mutable sequences.......8 Overriding Sequences Operations........8 Mappings (dictionaries).......................8 Operations on Mappings.......................8 Overriding Mapping Operations............8 Other Mappings.....................................9 Sets.....................................................9 Operations on Sets................................9 Other Containers Structures, Algorithms..........................................9 Array.....................................................9 Queue...................................................9 Priority Queues.....................................9 Sorted List.............................................9 Iteration Tools.......................................9 Date & Time........................................9 Module time..........................................9 Module datetime.................................10 Module timeit......................................10 Other Modules.....................................10 Files..................................................10 File Objects.........................................10 Low-level Files.....................................10 Pipes...................................................10 In-memory Files..................................10 Files Informations................................11 Terminal Operations...........................11 Temporary Files..................................11 Path Manipulations..............................11 Directories...........................................11 Special Files........................................12 Copying, Moving, Removing...............12 Encoded Files......................................12 Serialization........................................12 Persistence..........................................12 Configuration Files..............................12 Exceptions........................................12 Standard Exception Classes................12 Warnings.............................................13 Exceptions Processing........................13 Encoding - Decoding.........................13 Threads & Synchronization...............13 Threading Functions...........................13 Threads...............................................13 Mutual Exclusion.................................13 Events.................................................13 Semaphores........................................13 Condition Variables.............................13 Synchronized Queues.........................13 Process.............................................13 Current Process...................................13 Signal Handling...................................14 Simple External Process Control.........14 Advanced External Process Control....15 XML Processing.................................15 SAX - Event-driven..............................15 DOM - In-memory Tree.......................16 Databases.........................................17 Generic access to DBM-style DBs.......17 Standard DB API for SQL databases....17 Bulk...................................................18

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值