{ "cells": [ { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# IPython: beyond plain Python" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "When executing code in IPython, all valid Python syntax works as-is, but IPython provides a number of features designed to make the interactive experience more fluid and efficient." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## First things first: running code, getting help" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the notebook, to run a cell of code, hit `Shift-Enter`. This executes the cell and puts the cursor in the next cell below, or makes a new one if you are at the end. Alternately, you can use:\n", " \n", "- `Alt-Enter` to force the creation of a new cell unconditionally (useful when inserting new content in the middle of an existing notebook).\n", "- `Control-Enter` executes the cell and keeps the cursor in the same cell, useful for quick experimentation of snippets that you don't need to keep permanently." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Hi\n" ] } ], "source": [ "print(\"Hi\")" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "Getting help:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\n", "IPython -- An enhanced Interactive Python\n", "=========================================\n", "\n", "IPython offers a fully compatible replacement for the standard Python\n", "interpreter, with convenient shell features, special commands, command\n", "history mechanism and output results caching.\n", "\n", "At your system command line, type 'ipython -h' to see the command line\n", "options available. This document only describes interactive features.\n", "\n", "GETTING HELP\n", "------------\n", "\n", "Within IPython you have various way to access help:\n", "\n", " ? -> Introduction and overview of IPython's features (this screen).\n", " object? -> Details about 'object'.\n", " object?? -> More detailed, verbose information about 'object'.\n", " %quickref -> Quick reference of all IPython specific syntax and magics.\n", " help -> Access Python's own help system.\n", "\n", "If you are in terminal IPython you can quit this screen by pressing `q`.\n", "\n", "\n", "MAIN FEATURES\n", "-------------\n", "\n", "* Access to the standard Python help with object docstrings and the Python\n", " manuals. Simply type 'help' (no quotes) to invoke it.\n", "\n", "* Magic commands: type %magic for information on the magic subsystem.\n", "\n", "* System command aliases, via the %alias command or the configuration file(s).\n", "\n", "* Dynamic object information:\n", "\n", " Typing ?word or word? prints detailed information about an object. Certain\n", " long strings (code, etc.) get snipped in the center for brevity.\n", "\n", " Typing ??word or word?? gives access to the full information without\n", " snipping long strings. Strings that are longer than the screen are printed\n", " through the less pager.\n", "\n", " The ?/?? system gives access to the full source code for any object (if\n", " available), shows function prototypes and other useful information.\n", "\n", " If you just want to see an object's docstring, type '%pdoc object' (without\n", " quotes, and without % if you have automagic on).\n", "\n", "* Tab completion in the local namespace:\n", "\n", " At any time, hitting tab will complete any available python commands or\n", " variable names, and show you a list of the possible completions if there's\n", " no unambiguous one. It will also complete filenames in the current directory.\n", "\n", "* Search previous command history in multiple ways:\n", "\n", " - Start typing, and then use arrow keys up/down or (Ctrl-p/Ctrl-n) to search\n", " through the history items that match what you've typed so far.\n", "\n", " - Hit Ctrl-r: opens a search prompt. Begin typing and the system searches\n", " your history for lines that match what you've typed so far, completing as\n", " much as it can.\n", "\n", " - %hist: search history by index.\n", "\n", "* Persistent command history across sessions.\n", "\n", "* Logging of input with the ability to save and restore a working session.\n", "\n", "* System shell with !. Typing !ls will run 'ls' in the current directory.\n", "\n", "* The reload command does a 'deep' reload of a module: changes made to the\n", " module since you imported will actually be available without having to exit.\n", "\n", "* Verbose and colored exception traceback printouts. See the magic xmode and\n", " xcolor functions for details (just type %magic).\n", "\n", "* Input caching system:\n", "\n", " IPython offers numbered prompts (In/Out) with input and output caching. All\n", " input is saved and can be retrieved as variables (besides the usual arrow\n", " key recall).\n", "\n", " The following GLOBAL variables always exist (so don't overwrite them!):\n", " _i: stores previous input.\n", " _ii: next previous.\n", " _iii: next-next previous.\n", " _ih : a list of all input _ih[n] is the input from line n.\n", "\n", " Additionally, global variables named _i<n> are dynamically created (<n>\n", " being the prompt counter), such that _i<n> == _ih[<n>]\n", "\n", " For example, what you typed at prompt 14 is available as _i14 and _ih[14].\n", "\n", " You can create macros which contain multiple input lines from this history,\n", " for later re-execution, with the %macro function.\n", "\n", " The history function %hist allows you to see any part of your input history\n", " by printing a range of the _i variables. Note that inputs which contain\n", " magic functions (%) appear in the history with a prepended comment. This is\n", " because they aren't really valid Python code, so you can't exec them.\n", "\n", "* Output caching system:\n", "\n", " For output that is returned from actions, a system similar to the input\n", " cache exists but using _ instead of _i. Only actions that produce a result\n", " (NOT assignments, for example) are cached. If you are familiar with\n", " Mathematica, IPython's _ variables behave exactly like Mathematica's %\n", " variables.\n", "\n", " The following GLOBAL variables always exist (so don't overwrite them!):\n", " _ (one underscore): previous output.\n", " __ (two underscores): next previous.\n", " ___ (three underscores): next-next previous.\n", "\n", " Global variables named _<n> are dynamically created (<n> being the prompt\n", " counter), such that the result of output <n> is always available as _<n>.\n", "\n", " Finally, a global dictionary named _oh exists with entries for all lines\n", " which generated output.\n", "\n", "* Directory history:\n", "\n", " Your history of visited directories is kept in the global list _dh, and the\n", " magic %cd command can be used to go to any entry in that list.\n", "\n", "* Auto-parentheses and auto-quotes (adapted from Nathan Gray's LazyPython)\n", "\n", " 1. Auto-parentheses\n", " \n", " Callable objects (i.e. functions, methods, etc) can be invoked like\n", " this (notice the commas between the arguments)::\n", " \n", " In [1]: callable_ob arg1, arg2, arg3\n", " \n", " and the input will be translated to this::\n", " \n", " callable_ob(arg1, arg2, arg3)\n", " \n", " This feature is off by default (in rare cases it can produce\n", " undesirable side-effects), but you can activate it at the command-line\n", " by starting IPython with `--autocall 1`, set it permanently in your\n", " configuration file, or turn on at runtime with `%autocall 1`.\n", "\n", " You can force auto-parentheses by using '/' as the first character\n", " of a line. For example::\n", " \n", " In [1]: /globals # becomes 'globals()'\n", " \n", " Note that the '/' MUST be the first character on the line! This\n", " won't work::\n", " \n", " In [2]: print /globals # syntax error\n", "\n", " In most cases the automatic algorithm should work, so you should\n", " rarely need to explicitly invoke /. One notable exception is if you\n", " are trying to call a function with a list of tuples as arguments (the\n", " parenthesis will confuse IPython)::\n", " \n", " In [1]: zip (1,2,3),(4,5,6) # won't work\n", " \n", " but this will work::\n", " \n", " In [2]: /zip (1,2,3),(4,5,6)\n", " ------> zip ((1,2,3),(4,5,6))\n", " Out[2]= [(1, 4), (2, 5), (3, 6)]\n", "\n", " IPython tells you that it has altered your command line by\n", " displaying the new command line preceded by -->. e.g.::\n", " \n", " In [18]: callable list\n", " -------> callable (list)\n", "\n", " 2. Auto-Quoting\n", " \n", " You can force auto-quoting of a function's arguments by using ',' as\n", " the first character of a line. For example::\n", " \n", " In [1]: ,my_function /home/me # becomes my_function(\"/home/me\")\n", "\n", " If you use ';' instead, the whole argument is quoted as a single\n", " string (while ',' splits on whitespace)::\n", " \n", " In [2]: ,my_function a b c # becomes my_function(\"a\",\"b\",\"c\")\n", " In [3]: ;my_function a b c # becomes my_function(\"a b c\")\n", "\n", " Note that the ',' MUST be the first character on the line! This\n", " won't work::\n", " \n", " In [4]: x = ,my_function /home/me # syntax error\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "?" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "Typing `object_name?` will print all sorts of details about any object, including docstrings, function definition lines (for call arguments) and constructor details for classes." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\u001b[0;31mSignature:\u001b[0m\n", "\u001b[0mcollections\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnamedtuple\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mtypename\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mfield_names\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mverbose\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mrename\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mmodule\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mDocstring:\u001b[0m\n", "Returns a new subclass of tuple with named fields.\n", "\n", ">>> Point = namedtuple('Point', ['x', 'y'])\n", ">>> Point.__doc__ # docstring for the new class\n", "'Point(x, y)'\n", ">>> p = Point(11, y=22) # instantiate with positional args or keywords\n", ">>> p[0] + p[1] # indexable like a plain tuple\n", "33\n", ">>> x, y = p # unpack like a regular tuple\n", ">>> x, y\n", "(11, 22)\n", ">>> p.x + p.y # fields also accessible by name\n", "33\n", ">>> d = p._asdict() # convert to a dictionary\n", ">>> d['x']\n", "11\n", ">>> Point(**d) # convert from a dictionary\n", "Point(x=11, y=22)\n", ">>> p._replace(x=100) # _replace() is like str.replace() but targets named fields\n", "Point(x=100, y=22)\n", "\u001b[0;31mFile:\u001b[0m /usr/local/software/jureca/Stages/Devel-2019a/software/Python/3.6.8-GCCcore-8.3.0/lib/python3.6/collections/__init__.py\n", "\u001b[0;31mType:\u001b[0m function\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import collections\n", "collections.namedtuple?" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\u001b[0;31mInit signature:\u001b[0m \u001b[0mcollections\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mCounter\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwds\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mSource:\u001b[0m \n", "\u001b[0;32mclass\u001b[0m \u001b[0mCounter\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdict\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;34m'''Dict subclass for counting hashable items. Sometimes called a bag\u001b[0m\n", "\u001b[0;34m or multiset. Elements are stored as dictionary keys and their counts\u001b[0m\n", "\u001b[0;34m are stored as dictionary values.\u001b[0m\n", "\u001b[0;34m\u001b[0m\n", "\u001b[0;34m >>> c = Counter('abcdeabcdabcaba') # count elements from a string\u001b[0m\n", "\u001b[0;34m\u001b[0m\n", "\u001b[0;34m >>> c.most_common(3) # three most common elements\u001b[0m\n", "\u001b[0;34m [('a', 5), ('b', 4), ('c', 3)]\u001b[0m\n", "\u001b[0;34m >>> sorted(c) # list all unique elements\u001b[0m\n", "\u001b[0;34m ['a', 'b', 'c', 'd', 'e']\u001b[0m\n", "\u001b[0;34m >>> ''.join(sorted(c.elements())) # list elements with repetitions\u001b[0m\n", "\u001b[0;34m 'aaaaabbbbcccdde'\u001b[0m\n", "\u001b[0;34m >>> sum(c.values()) # total of all counts\u001b[0m\n", "\u001b[0;34m 15\u001b[0m\n", "\u001b[0;34m\u001b[0m\n", "\u001b[0;34m >>> c['a'] # count of letter 'a'\u001b[0m\n", "\u001b[0;34m 5\u001b[0m\n", "\u001b[0;34m >>> for elem in 'shazam': # update counts from an iterable\u001b[0m\n", "\u001b[0;34m ... c[elem] += 1 # by adding 1 to each element's count\u001b[0m\n", "\u001b[0;34m >>> c['a'] # now there are seven 'a'\u001b[0m\n", "\u001b[0;34m 7\u001b[0m\n", "\u001b[0;34m >>> del c['b'] # remove all 'b'\u001b[0m\n", "\u001b[0;34m >>> c['b'] # now there are zero 'b'\u001b[0m\n", "\u001b[0;34m 0\u001b[0m\n", "\u001b[0;34m\u001b[0m\n", "\u001b[0;34m >>> d = Counter('simsalabim') # make another counter\u001b[0m\n", "\u001b[0;34m >>> c.update(d) # add in the second counter\u001b[0m\n", "\u001b[0;34m >>> c['a'] # now there are nine 'a'\u001b[0m\n", "\u001b[0;34m 9\u001b[0m\n", "\u001b[0;34m\u001b[0m\n", "\u001b[0;34m >>> c.clear() # empty the counter\u001b[0m\n", "\u001b[0;34m >>> c\u001b[0m\n", "\u001b[0;34m Counter()\u001b[0m\n", "\u001b[0;34m\u001b[0m\n", "\u001b[0;34m Note: If a count is set to zero or reduced to zero, it will remain\u001b[0m\n", "\u001b[0;34m in the counter until the entry is deleted or the counter is cleared:\u001b[0m\n", "\u001b[0;34m\u001b[0m\n", "\u001b[0;34m >>> c = Counter('aaabbc')\u001b[0m\n", "\u001b[0;34m >>> c['b'] -= 2 # reduce the count of 'b' by two\u001b[0m\n", "\u001b[0;34m >>> c.most_common() # 'b' is still in, but its count is zero\u001b[0m\n", "\u001b[0;34m [('a', 3), ('c', 1), ('b', 0)]\u001b[0m\n", "\u001b[0;34m\u001b[0m\n", "\u001b[0;34m '''\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;31m# References:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;31m# http://en.wikipedia.org/wiki/Multiset\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;31m# http://www.gnu.org/software/smalltalk/manual-base/html_node/Bag.html\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;31m# http://www.demo2s.com/Tutorial/Cpp/0380__set-multiset/Catalog0380__set-multiset.htm\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;31m# http://code.activestate.com/recipes/259174/\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;31m# Knuth, TAOCP Vol. II section 4.6.3\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__init__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwds\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;34m'''Create a new, empty Counter object. And if given, count elements\u001b[0m\n", "\u001b[0;34m from an input iterable. Or, initialize the count from another mapping\u001b[0m\n", "\u001b[0;34m of elements to their counts.\u001b[0m\n", "\u001b[0;34m\u001b[0m\n", "\u001b[0;34m >>> c = Counter() # a new, empty counter\u001b[0m\n", "\u001b[0;34m >>> c = Counter('gallahad') # a new counter from an iterable\u001b[0m\n", "\u001b[0;34m >>> c = Counter({'a': 4, 'b': 2}) # a new counter from a mapping\u001b[0m\n", "\u001b[0;34m >>> c = Counter(a=4, b=2) # a new counter from keyword args\u001b[0m\n", "\u001b[0;34m\u001b[0m\n", "\u001b[0;34m '''\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0margs\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"descriptor '__init__' of 'Counter' object \"\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;34m\"needs an argument\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0margs\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m>\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'expected at most 1 arguments, got %d'\u001b[0m \u001b[0;34m%\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0msuper\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mCounter\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__init__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mupdate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwds\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__missing__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mkey\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;34m'The count of elements not in the Counter is zero.'\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;31m# Needed so that self[missing_item] does not raise KeyError\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mmost_common\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mn\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;34m'''List the n most common elements and their counts from the most\u001b[0m\n", "\u001b[0;34m common to the least. If n is None, then list all element counts.\u001b[0m\n", "\u001b[0;34m\u001b[0m\n", "\u001b[0;34m >>> Counter('abcdeabcdabcaba').most_common(3)\u001b[0m\n", "\u001b[0;34m [('a', 5), ('b', 4), ('c', 3)]\u001b[0m\n", "\u001b[0;34m\u001b[0m\n", "\u001b[0;34m '''\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;31m# Emulate Bag.sortedByCount from Smalltalk\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mn\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0msorted\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mitems\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mkey\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0m_itemgetter\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mreverse\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0m_heapq\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnlargest\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mn\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mitems\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mkey\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0m_itemgetter\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0melements\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;34m'''Iterator over elements repeating each as many times as its count.\u001b[0m\n", "\u001b[0;34m\u001b[0m\n", "\u001b[0;34m >>> c = Counter('ABCABC')\u001b[0m\n", "\u001b[0;34m >>> sorted(c.elements())\u001b[0m\n", "\u001b[0;34m ['A', 'A', 'B', 'B', 'C', 'C']\u001b[0m\n", "\u001b[0;34m\u001b[0m\n", "\u001b[0;34m # Knuth's example for prime factors of 1836: 2**2 * 3**3 * 17**1\u001b[0m\n", "\u001b[0;34m >>> prime_factors = Counter({2: 2, 3: 3, 17: 1})\u001b[0m\n", "\u001b[0;34m >>> product = 1\u001b[0m\n", "\u001b[0;34m >>> for factor in prime_factors.elements(): # loop over factors\u001b[0m\n", "\u001b[0;34m ... product *= factor # and multiply them\u001b[0m\n", "\u001b[0;34m >>> product\u001b[0m\n", "\u001b[0;34m 1836\u001b[0m\n", "\u001b[0;34m\u001b[0m\n", "\u001b[0;34m Note, if an element's count has been set to zero or is a negative\u001b[0m\n", "\u001b[0;34m number, elements() will ignore it.\u001b[0m\n", "\u001b[0;34m\u001b[0m\n", "\u001b[0;34m '''\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;31m# Emulate Bag.do from Smalltalk and Multiset.begin from C++.\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0m_chain\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfrom_iterable\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0m_starmap\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0m_repeat\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mitems\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;31m# Override dict methods where necessary\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;34m@\u001b[0m\u001b[0mclassmethod\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mfromkeys\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcls\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0miterable\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mv\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;31m# There is no equivalent method for counters because setting v=1\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;31m# means that no element can have a count greater than one.\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mNotImplementedError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;34m'Counter.fromkeys() is undefined. Use Counter(iterable) instead.'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mupdate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwds\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;34m'''Like dict.update() but add counts instead of replacing them.\u001b[0m\n", "\u001b[0;34m\u001b[0m\n", "\u001b[0;34m Source can be an iterable, a dictionary, or another Counter instance.\u001b[0m\n", "\u001b[0;34m\u001b[0m\n", "\u001b[0;34m >>> c = Counter('which')\u001b[0m\n", "\u001b[0;34m >>> c.update('witch') # add elements from another iterable\u001b[0m\n", "\u001b[0;34m >>> d = Counter('watch')\u001b[0m\n", "\u001b[0;34m >>> c.update(d) # add elements from another counter\u001b[0m\n", "\u001b[0;34m >>> c['h'] # four 'h' in which, witch, and watch\u001b[0m\n", "\u001b[0;34m 4\u001b[0m\n", "\u001b[0;34m\u001b[0m\n", "\u001b[0;34m '''\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;31m# The regular dict.update() operation makes no sense here because the\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;31m# replace behavior results in the some of original untouched counts\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;31m# being mixed-in with all of the other counts for a mismash that\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;31m# doesn't have a straight-forward interpretation in most counting\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;31m# contexts. Instead, we implement straight-addition. Both the inputs\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;31m# and outputs are allowed to contain zero and negative counts.\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0margs\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"descriptor 'update' of 'Counter' object \"\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;34m\"needs an argument\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0margs\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m>\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'expected at most 1 arguments, got %d'\u001b[0m \u001b[0;34m%\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0miterable\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0margs\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0margs\u001b[0m \u001b[0;32melse\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0miterable\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0miterable\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mMapping\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mself_get\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0melem\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcount\u001b[0m \u001b[0;32min\u001b[0m \u001b[0miterable\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mitems\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0melem\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcount\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mself_get\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0melem\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0msuper\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mCounter\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mupdate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0miterable\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# fast path when counter is empty\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0m_count_elements\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0miterable\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mkwds\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mupdate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mkwds\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0msubtract\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwds\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;34m'''Like dict.update() but subtracts counts instead of replacing them.\u001b[0m\n", "\u001b[0;34m Counts can be reduced below zero. Both the inputs and outputs are\u001b[0m\n", "\u001b[0;34m allowed to contain zero and negative counts.\u001b[0m\n", "\u001b[0;34m\u001b[0m\n", "\u001b[0;34m Source can be an iterable, a dictionary, or another Counter instance.\u001b[0m\n", "\u001b[0;34m\u001b[0m\n", "\u001b[0;34m >>> c = Counter('which')\u001b[0m\n", "\u001b[0;34m >>> c.subtract('witch') # subtract elements from another iterable\u001b[0m\n", "\u001b[0;34m >>> c.subtract(Counter('watch')) # subtract elements from another counter\u001b[0m\n", "\u001b[0;34m >>> c['h'] # 2 in which, minus 1 in witch, minus 1 in watch\u001b[0m\n", "\u001b[0;34m 0\u001b[0m\n", "\u001b[0;34m >>> c['w'] # 1 in which, minus 1 in witch, minus 1 in watch\u001b[0m\n", "\u001b[0;34m -1\u001b[0m\n", "\u001b[0;34m\u001b[0m\n", "\u001b[0;34m '''\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0margs\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"descriptor 'subtract' of 'Counter' object \"\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;34m\"needs an argument\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0margs\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m>\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'expected at most 1 arguments, got %d'\u001b[0m \u001b[0;34m%\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0miterable\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0margs\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0margs\u001b[0m \u001b[0;32melse\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0miterable\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mself_get\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0miterable\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mMapping\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0melem\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcount\u001b[0m \u001b[0;32min\u001b[0m \u001b[0miterable\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mitems\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0melem\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself_get\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0melem\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m-\u001b[0m \u001b[0mcount\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0melem\u001b[0m \u001b[0;32min\u001b[0m \u001b[0miterable\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0melem\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself_get\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0melem\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m-\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mkwds\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msubtract\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mkwds\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mcopy\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;34m'Return a shallow copy.'\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__class__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__reduce__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__class__\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mdict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__delitem__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0melem\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;34m'Like dict.__delitem__() but does not raise KeyError for missing values.'\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0melem\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0msuper\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__delitem__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0melem\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__repr__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0;34m'%s()'\u001b[0m \u001b[0;34m%\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__class__\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__name__\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mitems\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m', '\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mjoin\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmap\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'%r: %r'\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__mod__\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmost_common\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0;34m'%s({%s})'\u001b[0m \u001b[0;34m%\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__class__\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__name__\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mitems\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;31m# handle case where values are not orderable\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0;34m'{0}({1!r})'\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__class__\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__name__\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;31m# Multiset-style mathematical operations discussed in:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;31m# Knuth TAOCP Volume II section 4.6.3 exercise 19\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;31m# and at http://en.wikipedia.org/wiki/Multiset\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;31m#\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;31m# Outputs guaranteed to only include positive counts.\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;31m#\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;31m# To strip negative and zero counts, add-in an empty counter:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;31m# c += Counter()\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__add__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mother\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;34m'''Add counts from two counters.\u001b[0m\n", "\u001b[0;34m\u001b[0m\n", "\u001b[0;34m >>> Counter('abbb') + Counter('bcc')\u001b[0m\n", "\u001b[0;34m Counter({'b': 4, 'c': 2, 'a': 1})\u001b[0m\n", "\u001b[0;34m\u001b[0m\n", "\u001b[0;34m '''\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mother\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mCounter\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mNotImplemented\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mCounter\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0melem\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcount\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mitems\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mnewcount\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcount\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mother\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0melem\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mnewcount\u001b[0m \u001b[0;34m>\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0melem\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnewcount\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0melem\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcount\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mother\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mitems\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0melem\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0mcount\u001b[0m \u001b[0;34m>\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0melem\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcount\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__sub__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mother\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;34m''' Subtract count, but keep only results with positive counts.\u001b[0m\n", "\u001b[0;34m\u001b[0m\n", "\u001b[0;34m >>> Counter('abbbc') - Counter('bccd')\u001b[0m\n", "\u001b[0;34m Counter({'b': 2, 'a': 1})\u001b[0m\n", "\u001b[0;34m\u001b[0m\n", "\u001b[0;34m '''\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mother\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mCounter\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mNotImplemented\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mCounter\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0melem\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcount\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mitems\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mnewcount\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcount\u001b[0m \u001b[0;34m-\u001b[0m \u001b[0mother\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0melem\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mnewcount\u001b[0m \u001b[0;34m>\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0melem\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnewcount\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0melem\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcount\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mother\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mitems\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0melem\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0mcount\u001b[0m \u001b[0;34m<\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0melem\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m0\u001b[0m \u001b[0;34m-\u001b[0m \u001b[0mcount\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__or__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mother\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;34m'''Union is the maximum of value in either of the input counters.\u001b[0m\n", "\u001b[0;34m\u001b[0m\n", "\u001b[0;34m >>> Counter('abbb') | Counter('bcc')\u001b[0m\n", "\u001b[0;34m Counter({'b': 3, 'c': 2, 'a': 1})\u001b[0m\n", "\u001b[0;34m\u001b[0m\n", "\u001b[0;34m '''\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mother\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mCounter\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mNotImplemented\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mCounter\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0melem\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcount\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mitems\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mother_count\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mother\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0melem\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mnewcount\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mother_count\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mcount\u001b[0m \u001b[0;34m<\u001b[0m \u001b[0mother_count\u001b[0m \u001b[0;32melse\u001b[0m \u001b[0mcount\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mnewcount\u001b[0m \u001b[0;34m>\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0melem\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnewcount\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0melem\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcount\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mother\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mitems\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0melem\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0mcount\u001b[0m \u001b[0;34m>\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0melem\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcount\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__and__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mother\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;34m''' Intersection is the minimum of corresponding counts.\u001b[0m\n", "\u001b[0;34m\u001b[0m\n", "\u001b[0;34m >>> Counter('abbb') & Counter('bcc')\u001b[0m\n", "\u001b[0;34m Counter({'b': 1})\u001b[0m\n", "\u001b[0;34m\u001b[0m\n", "\u001b[0;34m '''\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mother\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mCounter\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mNotImplemented\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mCounter\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0melem\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcount\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mitems\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mother_count\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mother\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0melem\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mnewcount\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcount\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mcount\u001b[0m \u001b[0;34m<\u001b[0m \u001b[0mother_count\u001b[0m \u001b[0;32melse\u001b[0m \u001b[0mother_count\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mnewcount\u001b[0m \u001b[0;34m>\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0melem\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnewcount\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__pos__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;34m'Adds an empty counter, effectively stripping negative and zero counts'\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mCounter\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0melem\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcount\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mitems\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mcount\u001b[0m \u001b[0;34m>\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0melem\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcount\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__neg__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;34m'''Subtracts from an empty counter. Strips positive and zero counts,\u001b[0m\n", "\u001b[0;34m and flips the sign on negative counts.\u001b[0m\n", "\u001b[0;34m\u001b[0m\n", "\u001b[0;34m '''\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mCounter\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0melem\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcount\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mitems\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mcount\u001b[0m \u001b[0;34m<\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0melem\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m0\u001b[0m \u001b[0;34m-\u001b[0m \u001b[0mcount\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m_keep_positive\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;34m'''Internal method to strip elements with a negative or zero count'''\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mnonpositive\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0melem\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0melem\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcount\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mitems\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mcount\u001b[0m \u001b[0;34m>\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0melem\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mnonpositive\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mdel\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0melem\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__iadd__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mother\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;34m'''Inplace add from another counter, keeping only positive counts.\u001b[0m\n", "\u001b[0;34m\u001b[0m\n", "\u001b[0;34m >>> c = Counter('abbb')\u001b[0m\n", "\u001b[0;34m >>> c += Counter('bcc')\u001b[0m\n", "\u001b[0;34m >>> c\u001b[0m\n", "\u001b[0;34m Counter({'b': 4, 'c': 2, 'a': 1})\u001b[0m\n", "\u001b[0;34m\u001b[0m\n", "\u001b[0;34m '''\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0melem\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcount\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mother\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mitems\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0melem\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m+=\u001b[0m \u001b[0mcount\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_keep_positive\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__isub__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mother\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;34m'''Inplace subtract counter, but keep only results with positive counts.\u001b[0m\n", "\u001b[0;34m\u001b[0m\n", "\u001b[0;34m >>> c = Counter('abbbc')\u001b[0m\n", "\u001b[0;34m >>> c -= Counter('bccd')\u001b[0m\n", "\u001b[0;34m >>> c\u001b[0m\n", "\u001b[0;34m Counter({'b': 2, 'a': 1})\u001b[0m\n", "\u001b[0;34m\u001b[0m\n", "\u001b[0;34m '''\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0melem\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcount\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mother\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mitems\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0melem\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m-=\u001b[0m \u001b[0mcount\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_keep_positive\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__ior__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mother\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;34m'''Inplace union is the maximum of value from either counter.\u001b[0m\n", "\u001b[0;34m\u001b[0m\n", "\u001b[0;34m >>> c = Counter('abbb')\u001b[0m\n", "\u001b[0;34m >>> c |= Counter('bcc')\u001b[0m\n", "\u001b[0;34m >>> c\u001b[0m\n", "\u001b[0;34m Counter({'b': 3, 'c': 2, 'a': 1})\u001b[0m\n", "\u001b[0;34m\u001b[0m\n", "\u001b[0;34m '''\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0melem\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mother_count\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mother\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mitems\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mcount\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0melem\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mother_count\u001b[0m \u001b[0;34m>\u001b[0m \u001b[0mcount\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0melem\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mother_count\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_keep_positive\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__iand__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mother\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;34m'''Inplace intersection is the minimum of corresponding counts.\u001b[0m\n", "\u001b[0;34m\u001b[0m\n", "\u001b[0;34m >>> c = Counter('abbb')\u001b[0m\n", "\u001b[0;34m >>> c &= Counter('bcc')\u001b[0m\n", "\u001b[0;34m >>> c\u001b[0m\n", "\u001b[0;34m Counter({'b': 1})\u001b[0m\n", "\u001b[0;34m\u001b[0m\n", "\u001b[0;34m '''\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0melem\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcount\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mitems\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mother_count\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mother\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0melem\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mother_count\u001b[0m \u001b[0;34m<\u001b[0m \u001b[0mcount\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0melem\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mother_count\u001b[0m\u001b[0;34m\u001b[0m\n", "\u001b[0;34m\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_keep_positive\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mFile:\u001b[0m /usr/local/software/jureca/Stages/Devel-2019a/software/Python/3.6.8-GCCcore-8.3.0/lib/python3.6/collections/__init__.py\n", "\u001b[0;31mType:\u001b[0m type\n", "\u001b[0;31mSubclasses:\u001b[0m Counter\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "collections.Counter??" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "FloatingPointError\n", "int\n", "print" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "*int*?" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "An IPython quick reference card:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\n", "IPython -- An enhanced Interactive Python - Quick Reference Card\n", "================================================================\n", "\n", "obj?, obj?? : Get help, or more help for object (also works as\n", " ?obj, ??obj).\n", "?foo.*abc* : List names in 'foo' containing 'abc' in them.\n", "%magic : Information about IPython's 'magic' % functions.\n", "\n", "Magic functions are prefixed by % or %%, and typically take their arguments\n", "without parentheses, quotes or even commas for convenience. Line magics take a\n", "single % and cell magics are prefixed with two %%.\n", "\n", "Example magic function calls:\n", "\n", "%alias d ls -F : 'd' is now an alias for 'ls -F'\n", "alias d ls -F : Works if 'alias' not a python name\n", "alist = %alias : Get list of aliases to 'alist'\n", "cd /usr/share : Obvious. cd -<tab> to choose from visited dirs.\n", "%cd?? : See help AND source for magic %cd\n", "%timeit x=10 : time the 'x=10' statement with high precision.\n", "%%timeit x=2**100\n", "x**100 : time 'x**100' with a setup of 'x=2**100'; setup code is not\n", " counted. This is an example of a cell magic.\n", "\n", "System commands:\n", "\n", "!cp a.txt b/ : System command escape, calls os.system()\n", "cp a.txt b/ : after %rehashx, most system commands work without !\n", "cp ${f}.txt $bar : Variable expansion in magics and system commands\n", "files = !ls /usr : Capture system command output\n", "files.s, files.l, files.n: \"a b c\", ['a','b','c'], 'a\\nb\\nc'\n", "\n", "History:\n", "\n", "_i, _ii, _iii : Previous, next previous, next next previous input\n", "_i4, _ih[2:5] : Input history line 4, lines 2-4\n", "exec _i81 : Execute input history line #81 again\n", "%rep 81 : Edit input history line #81\n", "_, __, ___ : previous, next previous, next next previous output\n", "_dh : Directory history\n", "_oh : Output history\n", "%hist : Command history of current session.\n", "%hist -g foo : Search command history of (almost) all sessions for 'foo'.\n", "%hist -g : Command history of (almost) all sessions.\n", "%hist 1/2-8 : Command history containing lines 2-8 of session 1.\n", "%hist 1/ ~2/ : Command history of session 1 and 2 sessions before current.\n", "%hist ~8/1-~6/5 : Command history from line 1 of 8 sessions ago to\n", " line 5 of 6 sessions ago.\n", "%edit 0/ : Open editor to execute code with history of current session.\n", "\n", "Autocall:\n", "\n", "f 1,2 : f(1,2) # Off by default, enable with %autocall magic.\n", "/f 1,2 : f(1,2) (forced autoparen)\n", ",f 1 2 : f(\"1\",\"2\")\n", ";f 1 2 : f(\"1 2\")\n", "\n", "Remember: TAB completion works in many contexts, not just file names\n", "or python names.\n", "\n", "The following magic functions are currently available:\n", "\n", "%alias:\n", " Define an alias for a system command.\n", "%alias_magic:\n", " ::\n", "%autoawait:\n", " \n", "%autocall:\n", " Make functions callable without having to type parentheses.\n", "%automagic:\n", " Make magic functions callable without having to type the initial %.\n", "%autosave:\n", " Set the autosave interval in the notebook (in seconds).\n", "%bookmark:\n", " Manage IPython's bookmark system.\n", "%cat:\n", " Alias for `!cat`\n", "%cd:\n", " Change the current working directory.\n", "%clear:\n", " Clear the terminal.\n", "%colors:\n", " Switch color scheme for prompts, info system and exception handlers.\n", "%conda:\n", " Run the conda package manager within the current kernel.\n", "%config:\n", " configure IPython\n", "%connect_info:\n", " Print information for connecting other clients to this kernel\n", "%cp:\n", " Alias for `!cp`\n", "%debug:\n", " ::\n", "%dhist:\n", " Print your history of visited directories.\n", "%dirs:\n", " Return the current directory stack.\n", "%doctest_mode:\n", " Toggle doctest mode on and off.\n", "%ed:\n", " Alias for `%edit`.\n", "%edit:\n", " Bring up an editor and execute the resulting code.\n", "%env:\n", " Get, set, or list environment variables.\n", "%gui:\n", " Enable or disable IPython GUI event loop integration.\n", "%hist:\n", " Alias for `%history`.\n", "%history:\n", " ::\n", "%killbgscripts:\n", " Kill all BG processes started by %%script and its family.\n", "%ldir:\n", " Alias for `!ls -F -o --color %l | grep /$`\n", "%less:\n", " Show a file through the pager.\n", "%lf:\n", " Alias for `!ls -F -o --color %l | grep ^-`\n", "%lk:\n", " Alias for `!ls -F -o --color %l | grep ^l`\n", "%ll:\n", " Alias for `!ls -F -o --color`\n", "%load:\n", " Load code into the current frontend.\n", "%load_ext:\n", " Load an IPython extension by its module name.\n", "%loadpy:\n", " Alias of `%load`\n", "%logoff:\n", " Temporarily stop logging.\n", "%logon:\n", " Restart logging.\n", "%logstart:\n", " Start logging anywhere in a session.\n", "%logstate:\n", " Print the status of the logging system.\n", "%logstop:\n", " Fully stop logging and close log file.\n", "%ls:\n", " Alias for `!ls -F --color`\n", "%lsmagic:\n", " List currently available magic functions.\n", "%lx:\n", " Alias for `!ls -F -o --color %l | grep ^-..x`\n", "%macro:\n", " Define a macro for future re-execution. It accepts ranges of history,\n", "%magic:\n", " Print information about the magic function system.\n", "%man:\n", " Find the man page for the given command and display in pager.\n", "%matplotlib:\n", " ::\n", "%mkdir:\n", " Alias for `!mkdir`\n", "%more:\n", " Show a file through the pager.\n", "%mv:\n", " Alias for `!mv`\n", "%notebook:\n", " ::\n", "%page:\n", " Pretty print the object and display it through a pager.\n", "%pastebin:\n", " Upload code to dpaste's paste bin, returning the URL.\n", "%pdb:\n", " Control the automatic calling of the pdb interactive debugger.\n", "%pdef:\n", " Print the call signature for any callable object.\n", "%pdoc:\n", " Print the docstring for an object.\n", "%pfile:\n", " Print (or run through pager) the file where an object is defined.\n", "%pinfo:\n", " Provide detailed information about an object.\n", "%pinfo2:\n", " Provide extra detailed information about an object.\n", "%pip:\n", " Run the pip package manager within the current kernel.\n", "%popd:\n", " Change to directory popped off the top of the stack.\n", "%pprint:\n", " Toggle pretty printing on/off.\n", "%precision:\n", " Set floating point precision for pretty printing.\n", "%prun:\n", " Run a statement through the python code profiler.\n", "%psearch:\n", " Search for object in namespaces by wildcard.\n", "%psource:\n", " Print (or run through pager) the source code for an object.\n", "%pushd:\n", " Place the current dir on stack and change directory.\n", "%pwd:\n", " Return the current working directory path.\n", "%pycat:\n", " Show a syntax-highlighted file through a pager.\n", "%pylab:\n", " ::\n", "%qtconsole:\n", " Open a qtconsole connected to this kernel.\n", "%quickref:\n", " Show a quick reference sheet \n", "%recall:\n", " Repeat a command, or get command to input line for editing.\n", "%rehashx:\n", " Update the alias table with all executable files in $PATH.\n", "%reload_ext:\n", " Reload an IPython extension by its module name.\n", "%rep:\n", " Alias for `%recall`.\n", "%rerun:\n", " Re-run previous input\n", "%reset:\n", " Resets the namespace by removing all names defined by the user, if\n", "%reset_selective:\n", " Resets the namespace by removing names defined by the user.\n", "%rm:\n", " Alias for `!rm`\n", "%rmdir:\n", " Alias for `!rmdir`\n", "%run:\n", " Run the named file inside IPython as a program.\n", "%save:\n", " Save a set of lines or a macro to a given filename.\n", "%sc:\n", " Shell capture - run shell command and capture output (DEPRECATED use !).\n", "%set_env:\n", " Set environment variables. Assumptions are that either \"val\" is a\n", "%store:\n", " Lightweight persistence for python variables.\n", "%sx:\n", " Shell execute - run shell command and capture output (!! is short-hand).\n", "%system:\n", " Shell execute - run shell command and capture output (!! is short-hand).\n", "%tb:\n", " Print the last traceback.\n", "%time:\n", " Time execution of a Python statement or expression.\n", "%timeit:\n", " Time execution of a Python statement or expression\n", "%unalias:\n", " Remove an alias\n", "%unload_ext:\n", " Unload an IPython extension by its module name.\n", "%who:\n", " Print all interactive variables, with some minimal formatting.\n", "%who_ls:\n", " Return a sorted list of all interactive variables.\n", "%whos:\n", " Like %who, but gives some extra information about each variable.\n", "%xdel:\n", " Delete a variable, trying to clear it from anywhere that\n", "%xmode:\n", " Switch modes for the exception handlers.\n", "%%!:\n", " Shell execute - run shell command and capture output (!! is short-hand).\n", "%%HTML:\n", " Alias for `%%html`.\n", "%%SVG:\n", " Alias for `%%svg`.\n", "%%bash:\n", " %%bash script magic\n", "%%capture:\n", " ::\n", "%%debug:\n", " ::\n", "%%file:\n", " Alias for `%%writefile`.\n", "%%html:\n", " ::\n", "%%javascript:\n", " Run the cell block of Javascript code\n", "%%js:\n", " Run the cell block of Javascript code\n", "%%latex:\n", " Render the cell as a block of latex\n", "%%markdown:\n", " Render the cell as Markdown text block\n", "%%perl:\n", " %%perl script magic\n", "%%prun:\n", " Run a statement through the python code profiler.\n", "%%pypy:\n", " %%pypy script magic\n", "%%python:\n", " %%python script magic\n", "%%python2:\n", " %%python2 script magic\n", "%%python3:\n", " %%python3 script magic\n", "%%ruby:\n", " %%ruby script magic\n", "%%script:\n", " ::\n", "%%sh:\n", " %%sh script magic\n", "%%svg:\n", " Render the cell as an SVG literal\n", "%%sx:\n", " Shell execute - run shell command and capture output (!! is short-hand).\n", "%%system:\n", " Shell execute - run shell command and capture output (!! is short-hand).\n", "%%time:\n", " Time execution of a Python statement or expression.\n", "%%timeit:\n", " Time execution of a Python statement or expression\n", "%%writefile:\n", " ::\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%quickref" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Tab completion" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Tab completion, especially for attributes, is a convenient way to explore the structure of any object you’re dealing with. Simply type `object_name.<TAB>` to view the object’s attributes. Besides Python objects and keywords, tab completion also works on file and directory names." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "# collections." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## The interactive workflow: input, output, history" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "12" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "2+10" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "22" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "_+10" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "You can suppress the storage and rendering of output if you append `;` to the last cell (this comes in handy when plotting with matplotlib, for example):" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "10+20;" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "22" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "_" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "The output is stored in `_N` and `Out[N]` variables:" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "_9 == Out[9]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Previous inputs are available, too:" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "text/plain": [ "'_'" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "In[11]" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'In[11]'" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "_i" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " 1: print(\"Hi\")\n", " 2: ?\n", " 3:\n", "import collections\n", "collections.namedtuple?\n", " 4: collections.Counter??\n", " 5: *int*?\n" ] } ], "source": [ "%history -n 1-5" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "**Exercise**\n", "\n", "Write the last 10 lines of history to a file named `log.py`." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Accessing the underlying operating system" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/p/project/ccstvs/jupyter/j4j_notebooks/001-Tutorials/001-Basic-Tutorials/001-IPython-Kernel\n" ] } ], "source": [ "!pwd" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "My current directory's files:\n", "['Animations Using clear_output.ipynb', 'Background Jobs.ipynb', 'Beyond Plain Python.ipynb', 'Capturing Output.ipynb', 'Cell Magics.ipynb', 'Custom Display Logic.ipynb', 'Cython Magics.ipynb', 'foo.py', 'foo.pyx', 'images', 'mod.py', 'papermill_Animations Using clear_output.ipynb', 'papermill_Background Jobs.ipynb', 'papermill_Beyond Plain Python.ipynb', 'papermill_Capturing Output.ipynb', 'papermill_Cell Magics.ipynb', 'papermill_Custom Display Logic.ipynb', 'papermill_Cython Magics.ipynb', 'papermill_Plotting in the Notebook with Matplotlib.ipynb', 'papermill_Raw Input in the Notebook.ipynb', 'papermill_Rich Output.ipynb', 'papermill_Script Magics.ipynb', 'papermill_SymPy.ipynb', 'papermill_Working With External Code.ipynb', 'Plotting in the Notebook with Matplotlib.ipynb', '__pycache__', 'Raw Input in the Notebook.ipynb', 'Rich Output.ipynb', 'Script Magics.ipynb', 'script.py', 'SymPy.ipynb', 'test.txt', 'Working With External Code.ipynb']\n" ] } ], "source": [ "files = !ls\n", "print(\"My current directory's files:\")\n", "print(files)" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[Animations Using clear_output.ipynb, Background Jobs.ipynb, Beyond Plain Python.ipynb, Capturing Output.ipynb, Cell Magics.ipynb, Custom Display Logic.ipynb, Cython Magics.ipynb, foo.py, foo.pyx, images, mod.py, papermill_Animations Using clear_output.ipynb, papermill_Background Jobs.ipynb, papermill_Beyond Plain Python.ipynb, papermill_Capturing Output.ipynb, papermill_Cell Magics.ipynb, papermill_Custom Display Logic.ipynb, papermill_Cython Magics.ipynb, papermill_Plotting in the Notebook with Matplotlib.ipynb, papermill_Raw Input in the Notebook.ipynb, papermill_Rich Output.ipynb, papermill_Script Magics.ipynb, papermill_SymPy.ipynb, papermill_Working With External Code.ipynb, Plotting in the Notebook with Matplotlib.ipynb, __pycache__, Raw Input in the Notebook.ipynb, Rich Output.ipynb, Script Magics.ipynb, script.py, SymPy.ipynb, test.txt, Working With External Code.ipynb]\n" ] } ], "source": [ "!echo $files" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "ANIMATIONS USING CLEAR_OUTPUT.IPYNB\n" ] } ], "source": [ "!echo {files[0].upper()}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note that all this is available even in multiline blocks:" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "00 - Animations Using clear_output\n", "01 - Background Jobs\n", "02 - Beyond Plain Python\n", "03 - Capturing Output\n", "04 - Cell Magics\n", "05 - Custom Display Logic\n", "06 - Cython Magics\n", "--\n", "--\n", "--\n", "--\n", "11 - papermill_Animations Using clear_output\n", "12 - papermill_Background Jobs\n", "13 - papermill_Beyond Plain Python\n", "14 - papermill_Capturing Output\n", "15 - papermill_Cell Magics\n", "16 - papermill_Custom Display Logic\n", "17 - papermill_Cython Magics\n", "18 - papermill_Plotting in the Notebook with Matplotlib\n", "19 - papermill_Raw Input in the Notebook\n", "20 - papermill_Rich Output\n", "21 - papermill_Script Magics\n", "22 - papermill_SymPy\n", "23 - papermill_Working With External Code\n", "24 - Plotting in the Notebook with Matplotlib\n", "--\n", "26 - Raw Input in the Notebook\n", "27 - Rich Output\n", "28 - Script Magics\n", "--\n", "30 - SymPy\n", "--\n", "32 - Working With External Code\n" ] } ], "source": [ "import os\n", "for i,f in enumerate(files):\n", " if f.endswith('ipynb'):\n", " !echo {\"%02d\" % i} - \"{os.path.splitext(f)[0]}\"\n", " else:\n", " print('--')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Beyond Python: magic functions" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The IPyhton 'magic' functions are a set of commands, invoked by prepending one or two `%` signs to their name, that live in a namespace separate from your normal Python variables and provide a more command-like interface. They take flags with `--` and arguments without quotes, parentheses or commas. The motivation behind this system is two-fold:\n", " \n", "- To provide an orthogonal namespace for controlling IPython itself and exposing other system-oriented functionality.\n", "\n", "- To expose a calling mode that requires minimal verbosity and typing while working interactively. Thus the inspiration taken from the classic Unix shell style for commands." ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\n", "IPython's 'magic' functions\n", "===========================\n", "\n", "The magic function system provides a series of functions which allow you to\n", "control the behavior of IPython itself, plus a lot of system-type\n", "features. There are two kinds of magics, line-oriented and cell-oriented.\n", "\n", "Line magics are prefixed with the % character and work much like OS\n", "command-line calls: they get as an argument the rest of the line, where\n", "arguments are passed without parentheses or quotes. For example, this will\n", "time the given statement::\n", "\n", " %timeit range(1000)\n", "\n", "Cell magics are prefixed with a double %%, and they are functions that get as\n", "an argument not only the rest of the line, but also the lines below it in a\n", "separate argument. These magics are called with two arguments: the rest of the\n", "call line and the body of the cell, consisting of the lines below the first.\n", "For example::\n", "\n", " %%timeit x = numpy.random.randn((100, 100))\n", " numpy.linalg.svd(x)\n", "\n", "will time the execution of the numpy svd routine, running the assignment of x\n", "as part of the setup phase, which is not timed.\n", "\n", "In a line-oriented client (the terminal or Qt console IPython), starting a new\n", "input with %% will automatically enter cell mode, and IPython will continue\n", "reading input until a blank line is given. In the notebook, simply type the\n", "whole cell as one entity, but keep in mind that the %% escape can only be at\n", "the very start of the cell.\n", "\n", "NOTE: If you have 'automagic' enabled (via the command line option or with the\n", "%automagic function), you don't need to type in the % explicitly for line\n", "magics; cell magics always require an explicit '%%' escape. By default,\n", "IPython ships with automagic on, so you should only rarely need the % escape.\n", "\n", "Example: typing '%cd mydir' (without the quotes) changes your working directory\n", "to 'mydir', if it exists.\n", "\n", "For a list of the available magic functions, use %lsmagic. For a description\n", "of any of them, type %magic_name?, e.g. '%cd?'.\n", "\n", "Currently the magic system has the following functions:\n", "%alias:\n", " Define an alias for a system command.\n", " \n", " '%alias alias_name cmd' defines 'alias_name' as an alias for 'cmd'\n", " \n", " Then, typing 'alias_name params' will execute the system command 'cmd\n", " params' (from your underlying operating system).\n", " \n", " Aliases have lower precedence than magic functions and Python normal\n", " variables, so if 'foo' is both a Python variable and an alias, the\n", " alias can not be executed until 'del foo' removes the Python variable.\n", " \n", " You can use the %l specifier in an alias definition to represent the\n", " whole line when the alias is called. For example::\n", " \n", " In [2]: alias bracket echo \"Input in brackets: <%l>\"\n", " In [3]: bracket hello world\n", " Input in brackets: <hello world>\n", " \n", " You can also define aliases with parameters using %s specifiers (one\n", " per parameter)::\n", " \n", " In [1]: alias parts echo first %s second %s\n", " In [2]: %parts A B\n", " first A second B\n", " In [3]: %parts A\n", " Incorrect number of arguments: 2 expected.\n", " parts is an alias to: 'echo first %s second %s'\n", " \n", " Note that %l and %s are mutually exclusive. You can only use one or\n", " the other in your aliases.\n", " \n", " Aliases expand Python variables just like system calls using ! or !!\n", " do: all expressions prefixed with '$' get expanded. For details of\n", " the semantic rules, see PEP-215:\n", " http://www.python.org/peps/pep-0215.html. This is the library used by\n", " IPython for variable expansion. If you want to access a true shell\n", " variable, an extra $ is necessary to prevent its expansion by\n", " IPython::\n", " \n", " In [6]: alias show echo\n", " In [7]: PATH='A Python string'\n", " In [8]: show $PATH\n", " A Python string\n", " In [9]: show $$PATH\n", " /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:...\n", " \n", " You can use the alias facility to access all of $PATH. See the %rehashx\n", " function, which automatically creates aliases for the contents of your\n", " $PATH.\n", " \n", " If called with no parameters, %alias prints the current alias table\n", " for your system. For posix systems, the default aliases are 'cat',\n", " 'cp', 'mv', 'rm', 'rmdir', and 'mkdir', and other platform-specific\n", " aliases are added. For windows-based systems, the default aliases are\n", " 'copy', 'ddir', 'echo', 'ls', 'ldir', 'mkdir', 'ren', and 'rmdir'.\n", " \n", " You can see the definition of alias by adding a question mark in the\n", " end::\n", " \n", " In [1]: cat?\n", " Repr: <alias cat for 'cat'>\n", "%alias_magic:\n", " ::\n", " \n", " %alias_magic [-l] [-c] [-p PARAMS] name target\n", " \n", " Create an alias for an existing line or cell magic.\n", " \n", " Examples\n", " --------\n", " ::\n", " \n", " In [1]: %alias_magic t timeit\n", " Created `%t` as an alias for `%timeit`.\n", " Created `%%t` as an alias for `%%timeit`.\n", " \n", " In [2]: %t -n1 pass\n", " 1 loops, best of 3: 954 ns per loop\n", " \n", " In [3]: %%t -n1\n", " ...: pass\n", " ...:\n", " 1 loops, best of 3: 954 ns per loop\n", " \n", " In [4]: %alias_magic --cell whereami pwd\n", " UsageError: Cell magic function `%%pwd` not found.\n", " In [5]: %alias_magic --line whereami pwd\n", " Created `%whereami` as an alias for `%pwd`.\n", " \n", " In [6]: %whereami\n", " Out[6]: u'/home/testuser'\n", " \n", " In [7]: %alias_magic h history \"-p -l 30\" --line\n", " Created `%h` as an alias for `%history -l 30`.\n", " \n", " positional arguments:\n", " name Name of the magic to be created.\n", " target Name of the existing line or cell magic.\n", " \n", " optional arguments:\n", " -l, --line Create a line magic alias.\n", " -c, --cell Create a cell magic alias.\n", " -p PARAMS, --params PARAMS\n", " Parameters passed to the magic function.\n", "%autoawait:\n", " \n", " Allow to change the status of the autoawait option.\n", " \n", " This allow you to set a specific asynchronous code runner.\n", " \n", " If no value is passed, print the currently used asynchronous integration\n", " and whether it is activated.\n", " \n", " It can take a number of value evaluated in the following order:\n", " \n", " - False/false/off deactivate autoawait integration\n", " - True/true/on activate autoawait integration using configured default\n", " loop\n", " - asyncio/curio/trio activate autoawait integration and use integration\n", " with said library.\n", " \n", " - `sync` turn on the pseudo-sync integration (mostly used for\n", " `IPython.embed()` which does not run IPython with a real eventloop and\n", " deactivate running asynchronous code. Turning on Asynchronous code with\n", " the pseudo sync loop is undefined behavior and may lead IPython to crash.\n", " \n", " If the passed parameter does not match any of the above and is a python\n", " identifier, get said object from user namespace and set it as the\n", " runner, and activate autoawait. \n", " \n", " If the object is a fully qualified object name, attempt to import it and\n", " set it as the runner, and activate autoawait.\n", " \n", " \n", " The exact behavior of autoawait is experimental and subject to change\n", " across version of IPython and Python.\n", "%autocall:\n", " Make functions callable without having to type parentheses.\n", " \n", " Usage:\n", " \n", " %autocall [mode]\n", " \n", " The mode can be one of: 0->Off, 1->Smart, 2->Full. If not given, the\n", " value is toggled on and off (remembering the previous state).\n", " \n", " In more detail, these values mean:\n", " \n", " 0 -> fully disabled\n", " \n", " 1 -> active, but do not apply if there are no arguments on the line.\n", " \n", " In this mode, you get::\n", " \n", " In [1]: callable\n", " Out[1]: <built-in function callable>\n", " \n", " In [2]: callable 'hello'\n", " ------> callable('hello')\n", " Out[2]: False\n", " \n", " 2 -> Active always. Even if no arguments are present, the callable\n", " object is called::\n", " \n", " In [2]: float\n", " ------> float()\n", " Out[2]: 0.0\n", " \n", " Note that even with autocall off, you can still use '/' at the start of\n", " a line to treat the first argument on the command line as a function\n", " and add parentheses to it::\n", " \n", " In [8]: /str 43\n", " ------> str(43)\n", " Out[8]: '43'\n", " \n", " # all-random (note for auto-testing)\n", "%automagic:\n", " Make magic functions callable without having to type the initial %.\n", " \n", " Without arguments toggles on/off (when off, you must call it as\n", " %automagic, of course). With arguments it sets the value, and you can\n", " use any of (case insensitive):\n", " \n", " - on, 1, True: to activate\n", " \n", " - off, 0, False: to deactivate.\n", " \n", " Note that magic functions have lowest priority, so if there's a\n", " variable whose name collides with that of a magic fn, automagic won't\n", " work for that function (you get the variable instead). However, if you\n", " delete the variable (del var), the previously shadowed magic function\n", " becomes visible to automagic again.\n", "%autosave:\n", " Set the autosave interval in the notebook (in seconds).\n", " \n", " The default value is 120, or two minutes.\n", " ``%autosave 0`` will disable autosave.\n", " \n", " This magic only has an effect when called from the notebook interface.\n", " It has no effect when called in a startup file.\n", "%bookmark:\n", " Manage IPython's bookmark system.\n", " \n", " %bookmark <name> - set bookmark to current dir\n", " %bookmark <name> <dir> - set bookmark to <dir>\n", " %bookmark -l - list all bookmarks\n", " %bookmark -d <name> - remove bookmark\n", " %bookmark -r - remove all bookmarks\n", " \n", " You can later on access a bookmarked folder with::\n", " \n", " %cd -b <name>\n", " \n", " or simply '%cd <name>' if there is no directory called <name> AND\n", " there is such a bookmark defined.\n", " \n", " Your bookmarks persist through IPython sessions, but they are\n", " associated with each profile.\n", "%cat:\n", " Alias for `!cat`\n", "%cd:\n", " Change the current working directory.\n", " \n", " This command automatically maintains an internal list of directories\n", " you visit during your IPython session, in the variable _dh. The\n", " command %dhist shows this history nicely formatted. You can also\n", " do 'cd -<tab>' to see directory history conveniently.\n", " \n", " Usage:\n", " \n", " cd 'dir': changes to directory 'dir'.\n", " \n", " cd -: changes to the last visited directory.\n", " \n", " cd -<n>: changes to the n-th directory in the directory history.\n", " \n", " cd --foo: change to directory that matches 'foo' in history\n", " \n", " cd -b <bookmark_name>: jump to a bookmark set by %bookmark\n", " (note: cd <bookmark_name> is enough if there is no\n", " directory <bookmark_name>, but a bookmark with the name exists.)\n", " 'cd -b <tab>' allows you to tab-complete bookmark names.\n", " \n", " Options:\n", " \n", " -q: quiet. Do not print the working directory after the cd command is\n", " executed. By default IPython's cd command does print this directory,\n", " since the default prompts do not display path information.\n", " \n", " Note that !cd doesn't work for this purpose because the shell where\n", " !command runs is immediately discarded after executing 'command'.\n", " \n", " Examples\n", " --------\n", " ::\n", " \n", " In [10]: cd parent/child\n", " /home/tsuser/parent/child\n", "%clear:\n", " Clear the terminal.\n", "%colors:\n", " Switch color scheme for prompts, info system and exception handlers.\n", " \n", " Currently implemented schemes: NoColor, Linux, LightBG.\n", " \n", " Color scheme names are not case-sensitive.\n", " \n", " Examples\n", " --------\n", " To get a plain black and white terminal::\n", " \n", " %colors nocolor\n", "%conda:\n", " Run the conda package manager within the current kernel.\n", " \n", " Usage:\n", " %conda install [pkgs]\n", "%config:\n", " configure IPython\n", " \n", " %config Class[.trait=value]\n", " \n", " This magic exposes most of the IPython config system. Any\n", " Configurable class should be able to be configured with the simple\n", " line::\n", " \n", " %config Class.trait=value\n", " \n", " Where `value` will be resolved in the user's namespace, if it is an\n", " expression or variable name.\n", " \n", " Examples\n", " --------\n", " \n", " To see what classes are available for config, pass no arguments::\n", " \n", " In [1]: %config\n", " Available objects for config:\n", " TerminalInteractiveShell\n", " HistoryManager\n", " PrefilterManager\n", " AliasManager\n", " IPCompleter\n", " DisplayFormatter\n", " \n", " To view what is configurable on a given class, just pass the class\n", " name::\n", " \n", " In [2]: %config IPCompleter\n", " IPCompleter options\n", " -----------------\n", " IPCompleter.omit__names=<Enum>\n", " Current: 2\n", " Choices: (0, 1, 2)\n", " Instruct the completer to omit private method names\n", " Specifically, when completing on ``object.<tab>``.\n", " When 2 [default]: all names that start with '_' will be excluded.\n", " When 1: all 'magic' names (``__foo__``) will be excluded.\n", " When 0: nothing will be excluded.\n", " IPCompleter.merge_completions=<CBool>\n", " Current: True\n", " Whether to merge completion results into a single list\n", " If False, only the completion results from the first non-empty\n", " completer will be returned.\n", " IPCompleter.limit_to__all__=<CBool>\n", " Current: False\n", " Instruct the completer to use __all__ for the completion\n", " Specifically, when completing on ``object.<tab>``.\n", " When True: only those names in obj.__all__ will be included.\n", " When False [default]: the __all__ attribute is ignored\n", " IPCompleter.greedy=<CBool>\n", " Current: False\n", " Activate greedy completion\n", " This will enable completion on elements of lists, results of\n", " function calls, etc., but can be unsafe because the code is\n", " actually evaluated on TAB.\n", " \n", " but the real use is in setting values::\n", " \n", " In [3]: %config IPCompleter.greedy = True\n", " \n", " and these values are read from the user_ns if they are variables::\n", " \n", " In [4]: feeling_greedy=False\n", " \n", " In [5]: %config IPCompleter.greedy = feeling_greedy\n", "%connect_info:\n", " Print information for connecting other clients to this kernel\n", " \n", " It will print the contents of this session's connection file, as well as\n", " shortcuts for local clients.\n", " \n", " In the simplest case, when called from the most recently launched kernel,\n", " secondary clients can be connected, simply with:\n", " \n", " $> jupyter <app> --existing\n", "%cp:\n", " Alias for `!cp`\n", "%debug:\n", " ::\n", " \n", " %debug [--breakpoint FILE:LINE] [statement [statement ...]]\n", " \n", " Activate the interactive debugger.\n", " \n", " This magic command support two ways of activating debugger.\n", " One is to activate debugger before executing code. This way, you\n", " can set a break point, to step through the code from the point.\n", " You can use this mode by giving statements to execute and optionally\n", " a breakpoint.\n", " \n", " The other one is to activate debugger in post-mortem mode. You can\n", " activate this mode simply running %debug without any argument.\n", " If an exception has just occurred, this lets you inspect its stack\n", " frames interactively. Note that this will always work only on the last\n", " traceback that occurred, so you must call this quickly after an\n", " exception that you wish to inspect has fired, because if another one\n", " occurs, it clobbers the previous one.\n", " \n", " If you want IPython to automatically do this on every exception, see\n", " the %pdb magic for more details.\n", " \n", " .. versionchanged:: 7.3\n", " When running code, user variables are no longer expanded,\n", " the magic line is always left unmodified.\n", " \n", " positional arguments:\n", " statement Code to run in debugger. You can omit this in cell\n", " magic mode.\n", " \n", " optional arguments:\n", " --breakpoint <FILE:LINE>, -b <FILE:LINE>\n", " Set break point at LINE in FILE.\n", "%dhist:\n", " Print your history of visited directories.\n", " \n", " %dhist -> print full history\n", " %dhist n -> print last n entries only\n", " %dhist n1 n2 -> print entries between n1 and n2 (n2 not included)\n", " \n", " This history is automatically maintained by the %cd command, and\n", " always available as the global list variable _dh. You can use %cd -<n>\n", " to go to directory number <n>.\n", " \n", " Note that most of time, you should view directory history by entering\n", " cd -<TAB>.\n", "%dirs:\n", " Return the current directory stack.\n", "%doctest_mode:\n", " Toggle doctest mode on and off.\n", " \n", " This mode is intended to make IPython behave as much as possible like a\n", " plain Python shell, from the perspective of how its prompts, exceptions\n", " and output look. This makes it easy to copy and paste parts of a\n", " session into doctests. It does so by:\n", " \n", " - Changing the prompts to the classic ``>>>`` ones.\n", " - Changing the exception reporting mode to 'Plain'.\n", " - Disabling pretty-printing of output.\n", " \n", " Note that IPython also supports the pasting of code snippets that have\n", " leading '>>>' and '...' prompts in them. This means that you can paste\n", " doctests from files or docstrings (even if they have leading\n", " whitespace), and the code will execute correctly. You can then use\n", " '%history -t' to see the translated history; this will give you the\n", " input after removal of all the leading prompts and whitespace, which\n", " can be pasted back into an editor.\n", " \n", " With these features, you can switch into this mode easily whenever you\n", " need to do testing and changes to doctests, without having to leave\n", " your existing IPython session.\n", "%ed:\n", " Alias for `%edit`.\n", "%edit:\n", " Bring up an editor and execute the resulting code.\n", " \n", " Usage:\n", " %edit [options] [args]\n", " \n", " %edit runs an external text editor. You will need to set the command for\n", " this editor via the ``TerminalInteractiveShell.editor`` option in your\n", " configuration file before it will work.\n", " \n", " This command allows you to conveniently edit multi-line code right in\n", " your IPython session.\n", " \n", " If called without arguments, %edit opens up an empty editor with a\n", " temporary file and will execute the contents of this file when you\n", " close it (don't forget to save it!).\n", " \n", " Options:\n", " \n", " -n <number>\n", " Open the editor at a specified line number. By default, the IPython\n", " editor hook uses the unix syntax 'editor +N filename', but you can\n", " configure this by providing your own modified hook if your favorite\n", " editor supports line-number specifications with a different syntax.\n", " \n", " -p\n", " Call the editor with the same data as the previous time it was used,\n", " regardless of how long ago (in your current session) it was.\n", " \n", " -r\n", " Use 'raw' input. This option only applies to input taken from the\n", " user's history. By default, the 'processed' history is used, so that\n", " magics are loaded in their transformed version to valid Python. If\n", " this option is given, the raw input as typed as the command line is\n", " used instead. When you exit the editor, it will be executed by\n", " IPython's own processor.\n", " \n", " Arguments:\n", " \n", " If arguments are given, the following possibilities exist:\n", " \n", " - The arguments are numbers or pairs of colon-separated numbers (like\n", " 1 4:8 9). These are interpreted as lines of previous input to be\n", " loaded into the editor. The syntax is the same of the %macro command.\n", " \n", " - If the argument doesn't start with a number, it is evaluated as a\n", " variable and its contents loaded into the editor. You can thus edit\n", " any string which contains python code (including the result of\n", " previous edits).\n", " \n", " - If the argument is the name of an object (other than a string),\n", " IPython will try to locate the file where it was defined and open the\n", " editor at the point where it is defined. You can use ``%edit function``\n", " to load an editor exactly at the point where 'function' is defined,\n", " edit it and have the file be executed automatically.\n", " \n", " If the object is a macro (see %macro for details), this opens up your\n", " specified editor with a temporary file containing the macro's data.\n", " Upon exit, the macro is reloaded with the contents of the file.\n", " \n", " Note: opening at an exact line is only supported under Unix, and some\n", " editors (like kedit and gedit up to Gnome 2.8) do not understand the\n", " '+NUMBER' parameter necessary for this feature. Good editors like\n", " (X)Emacs, vi, jed, pico and joe all do.\n", " \n", " - If the argument is not found as a variable, IPython will look for a\n", " file with that name (adding .py if necessary) and load it into the\n", " editor. It will execute its contents with execfile() when you exit,\n", " loading any code in the file into your interactive namespace.\n", " \n", " Unlike in the terminal, this is designed to use a GUI editor, and we do\n", " not know when it has closed. So the file you edit will not be\n", " automatically executed or printed.\n", " \n", " Note that %edit is also available through the alias %ed.\n", "%env:\n", " Get, set, or list environment variables.\n", " \n", " Usage:\n", " \n", " %env: lists all environment variables/values\n", " %env var: get value for var\n", " %env var val: set value for var\n", " %env var=val: set value for var\n", " %env var=$val: set value for var, using python expansion if possible\n", "%gui:\n", " Enable or disable IPython GUI event loop integration.\n", " \n", " %gui [GUINAME]\n", " \n", " This magic replaces IPython's threaded shells that were activated\n", " using the (pylab/wthread/etc.) command line flags. GUI toolkits\n", " can now be enabled at runtime and keyboard\n", " interrupts should work without any problems. The following toolkits\n", " are supported: wxPython, PyQt4, PyGTK, Tk and Cocoa (OSX)::\n", " \n", " %gui wx # enable wxPython event loop integration\n", " %gui qt4|qt # enable PyQt4 event loop integration\n", " %gui qt5 # enable PyQt5 event loop integration\n", " %gui gtk # enable PyGTK event loop integration\n", " %gui gtk3 # enable Gtk3 event loop integration\n", " %gui tk # enable Tk event loop integration\n", " %gui osx # enable Cocoa event loop integration\n", " # (requires %matplotlib 1.1)\n", " %gui # disable all event loop integration\n", " \n", " WARNING: after any of these has been called you can simply create\n", " an application object, but DO NOT start the event loop yourself, as\n", " we have already handled that.\n", "%hist:\n", " Alias for `%history`.\n", "%history:\n", " ::\n", " \n", " %history [-n] [-o] [-p] [-t] [-f FILENAME] [-g [PATTERN [PATTERN ...]]]\n", " [-l [LIMIT]] [-u]\n", " [range [range ...]]\n", " \n", " Print input history (_i<n> variables), with most recent last.\n", " \n", " By default, input history is printed without line numbers so it can be\n", " directly pasted into an editor. Use -n to show them.\n", " \n", " By default, all input history from the current session is displayed.\n", " Ranges of history can be indicated using the syntax:\n", " \n", " ``4``\n", " Line 4, current session\n", " ``4-6``\n", " Lines 4-6, current session\n", " ``243/1-5``\n", " Lines 1-5, session 243\n", " ``~2/7``\n", " Line 7, session 2 before current\n", " ``~8/1-~6/5``\n", " From the first line of 8 sessions ago, to the fifth line of 6\n", " sessions ago.\n", " \n", " Multiple ranges can be entered, separated by spaces\n", " \n", " The same syntax is used by %macro, %save, %edit, %rerun\n", " \n", " Examples\n", " --------\n", " ::\n", " \n", " In [6]: %history -n 4-6\n", " 4:a = 12\n", " 5:print a**2\n", " 6:%history -n 4-6\n", " \n", " positional arguments:\n", " range\n", " \n", " optional arguments:\n", " -n print line numbers for each input. This feature is\n", " only available if numbered prompts are in use.\n", " -o also print outputs for each input.\n", " -p print classic '>>>' python prompts before each input.\n", " This is useful for making documentation, and in\n", " conjunction with -o, for producing doctest-ready\n", " output.\n", " -t print the 'translated' history, as IPython understands\n", " it. IPython filters your input and converts it all\n", " into valid Python source before executing it (things\n", " like magics or aliases are turned into function calls,\n", " for example). With this option, you'll see the native\n", " history instead of the user-entered version: '%cd /'\n", " will be seen as 'get_ipython().run_line_magic(\"cd\",\n", " \"/\")' instead of '%cd /'.\n", " -f FILENAME FILENAME: instead of printing the output to the\n", " screen, redirect it to the given file. The file is\n", " always overwritten, though *when it can*, IPython asks\n", " for confirmation first. In particular, running the\n", " command 'history -f FILENAME' from the IPython\n", " Notebook interface will replace FILENAME even if it\n", " already exists *without* confirmation.\n", " -g <[PATTERN [PATTERN ...]]>\n", " treat the arg as a glob pattern to search for in\n", " (full) history. This includes the saved history\n", " (almost all commands ever written). The pattern may\n", " contain '?' to match one unknown character and '*' to\n", " match any number of unknown characters. Use '%hist -g'\n", " to show full saved history (may be very long).\n", " -l <[LIMIT]> get the last n lines from all sessions. Specify n as a\n", " single arg, or the default is the last 10 lines.\n", " -u when searching history using `-g`, show only unique\n", " history.\n", "%killbgscripts:\n", " Kill all BG processes started by %%script and its family.\n", "%ldir:\n", " Alias for `!ls -F -o --color %l | grep /$`\n", "%less:\n", " Show a file through the pager.\n", " \n", " Files ending in .py are syntax-highlighted.\n", "%lf:\n", " Alias for `!ls -F -o --color %l | grep ^-`\n", "%lk:\n", " Alias for `!ls -F -o --color %l | grep ^l`\n", "%ll:\n", " Alias for `!ls -F -o --color`\n", "%load:\n", " Load code into the current frontend.\n", " \n", " Usage:\n", " %load [options] source\n", " \n", " where source can be a filename, URL, input history range, macro, or\n", " element in the user namespace\n", " \n", " Options:\n", " \n", " -r <lines>: Specify lines or ranges of lines to load from the source.\n", " Ranges could be specified as x-y (x..y) or in python-style x:y \n", " (x..(y-1)). Both limits x and y can be left blank (meaning the \n", " beginning and end of the file, respectively).\n", " \n", " -s <symbols>: Specify function or classes to load from python source. \n", " \n", " -y : Don't ask confirmation for loading source above 200 000 characters.\n", " \n", " -n : Include the user's namespace when searching for source code.\n", " \n", " This magic command can either take a local filename, a URL, an history\n", " range (see %history) or a macro as argument, it will prompt for\n", " confirmation before loading source with more than 200 000 characters, unless\n", " -y flag is passed or if the frontend does not support raw_input::\n", " \n", " %load myscript.py\n", " %load 7-27\n", " %load myMacro\n", " %load http://www.example.com/myscript.py\n", " %load -r 5-10 myscript.py\n", " %load -r 10-20,30,40: foo.py\n", " %load -s MyClass,wonder_function myscript.py\n", " %load -n MyClass\n", " %load -n my_module.wonder_function\n", "%load_ext:\n", " Load an IPython extension by its module name.\n", "%loadpy:\n", " Alias of `%load`\n", " \n", " `%loadpy` has gained some flexibility and dropped the requirement of a `.py`\n", " extension. So it has been renamed simply into %load. You can look at\n", " `%load`'s docstring for more info.\n", "%logoff:\n", " Temporarily stop logging.\n", " \n", " You must have previously started logging.\n", "%logon:\n", " Restart logging.\n", " \n", " This function is for restarting logging which you've temporarily\n", " stopped with %logoff. For starting logging for the first time, you\n", " must use the %logstart function, which allows you to specify an\n", " optional log filename.\n", "%logstart:\n", " Start logging anywhere in a session.\n", " \n", " %logstart [-o|-r|-t|-q] [log_name [log_mode]]\n", " \n", " If no name is given, it defaults to a file named 'ipython_log.py' in your\n", " current directory, in 'rotate' mode (see below).\n", " \n", " '%logstart name' saves to file 'name' in 'backup' mode. It saves your\n", " history up to that point and then continues logging.\n", " \n", " %logstart takes a second optional parameter: logging mode. This can be one\n", " of (note that the modes are given unquoted):\n", " \n", " append\n", " Keep logging at the end of any existing file.\n", " \n", " backup\n", " Rename any existing file to name~ and start name.\n", " \n", " global\n", " Append to a single logfile in your home directory.\n", " \n", " over\n", " Overwrite any existing log.\n", " \n", " rotate\n", " Create rotating logs: name.1~, name.2~, etc.\n", " \n", " Options:\n", " \n", " -o\n", " log also IPython's output. In this mode, all commands which\n", " generate an Out[NN] prompt are recorded to the logfile, right after\n", " their corresponding input line. The output lines are always\n", " prepended with a '#[Out]# ' marker, so that the log remains valid\n", " Python code.\n", " \n", " Since this marker is always the same, filtering only the output from\n", " a log is very easy, using for example a simple awk call::\n", " \n", " awk -F'#\\[Out\\]# ' '{if($2) {print $2}}' ipython_log.py\n", " \n", " -r\n", " log 'raw' input. Normally, IPython's logs contain the processed\n", " input, so that user lines are logged in their final form, converted\n", " into valid Python. For example, %Exit is logged as\n", " _ip.magic(\"Exit\"). If the -r flag is given, all input is logged\n", " exactly as typed, with no transformations applied.\n", " \n", " -t\n", " put timestamps before each input line logged (these are put in\n", " comments).\n", " \n", " -q \n", " suppress output of logstate message when logging is invoked\n", "%logstate:\n", " Print the status of the logging system.\n", "%logstop:\n", " Fully stop logging and close log file.\n", " \n", " In order to start logging again, a new %logstart call needs to be made,\n", " possibly (though not necessarily) with a new filename, mode and other\n", " options.\n", "%ls:\n", " Alias for `!ls -F --color`\n", "%lsmagic:\n", " List currently available magic functions.\n", "%lx:\n", " Alias for `!ls -F -o --color %l | grep ^-..x`\n", "%macro:\n", " Define a macro for future re-execution. It accepts ranges of history,\n", " filenames or string objects.\n", " \n", " Usage:\n", " %macro [options] name n1-n2 n3-n4 ... n5 .. n6 ...\n", " \n", " Options:\n", " \n", " -r: use 'raw' input. By default, the 'processed' history is used,\n", " so that magics are loaded in their transformed version to valid\n", " Python. If this option is given, the raw input as typed at the\n", " command line is used instead.\n", " \n", " -q: quiet macro definition. By default, a tag line is printed \n", " to indicate the macro has been created, and then the contents of \n", " the macro are printed. If this option is given, then no printout\n", " is produced once the macro is created.\n", " \n", " This will define a global variable called `name` which is a string\n", " made of joining the slices and lines you specify (n1,n2,... numbers\n", " above) from your input history into a single string. This variable\n", " acts like an automatic function which re-executes those lines as if\n", " you had typed them. You just type 'name' at the prompt and the code\n", " executes.\n", " \n", " The syntax for indicating input ranges is described in %history.\n", " \n", " Note: as a 'hidden' feature, you can also use traditional python slice\n", " notation, where N:M means numbers N through M-1.\n", " \n", " For example, if your history contains (print using %hist -n )::\n", " \n", " 44: x=1\n", " 45: y=3\n", " 46: z=x+y\n", " 47: print x\n", " 48: a=5\n", " 49: print 'x',x,'y',y\n", " \n", " you can create a macro with lines 44 through 47 (included) and line 49\n", " called my_macro with::\n", " \n", " In [55]: %macro my_macro 44-47 49\n", " \n", " Now, typing `my_macro` (without quotes) will re-execute all this code\n", " in one pass.\n", " \n", " You don't need to give the line-numbers in order, and any given line\n", " number can appear multiple times. You can assemble macros with any\n", " lines from your input history in any order.\n", " \n", " The macro is a simple object which holds its value in an attribute,\n", " but IPython's display system checks for macros and executes them as\n", " code instead of printing them when you type their name.\n", " \n", " You can view a macro's contents by explicitly printing it with::\n", " \n", " print macro_name\n", "%magic:\n", " Print information about the magic function system.\n", " \n", " Supported formats: -latex, -brief, -rest\n", "%man:\n", " Find the man page for the given command and display in pager.\n", "%matplotlib:\n", " ::\n", " \n", " %matplotlib [-l] [gui]\n", " \n", " Set up matplotlib to work interactively.\n", " \n", " This function lets you activate matplotlib interactive support\n", " at any point during an IPython session. It does not import anything\n", " into the interactive namespace.\n", " \n", " If you are using the inline matplotlib backend in the IPython Notebook\n", " you can set which figure formats are enabled using the following::\n", " \n", " In [1]: from IPython.display import set_matplotlib_formats\n", " \n", " In [2]: set_matplotlib_formats('pdf', 'svg')\n", " \n", " The default for inline figures sets `bbox_inches` to 'tight'. This can\n", " cause discrepancies between the displayed image and the identical\n", " image created using `savefig`. This behavior can be disabled using the\n", " `%config` magic::\n", " \n", " In [3]: %config InlineBackend.print_figure_kwargs = {'bbox_inches':None}\n", " \n", " In addition, see the docstring of\n", " `IPython.display.set_matplotlib_formats` and\n", " `IPython.display.set_matplotlib_close` for more information on\n", " changing additional behaviors of the inline backend.\n", " \n", " Examples\n", " --------\n", " To enable the inline backend for usage with the IPython Notebook::\n", " \n", " In [1]: %matplotlib inline\n", " \n", " In this case, where the matplotlib default is TkAgg::\n", " \n", " In [2]: %matplotlib\n", " Using matplotlib backend: TkAgg\n", " \n", " But you can explicitly request a different GUI backend::\n", " \n", " In [3]: %matplotlib qt\n", " \n", " You can list the available backends using the -l/--list option::\n", " \n", " In [4]: %matplotlib --list\n", " Available matplotlib backends: ['osx', 'qt4', 'qt5', 'gtk3', 'notebook', 'wx', 'qt', 'nbagg',\n", " 'gtk', 'tk', 'inline']\n", " \n", " positional arguments:\n", " gui Name of the matplotlib backend to use ('agg', 'gtk', 'gtk3',\n", " 'inline', 'ipympl', 'nbagg', 'notebook', 'osx', 'pdf', 'ps',\n", " 'qt', 'qt4', 'qt5', 'svg', 'tk', 'widget', 'wx'). If given, the\n", " corresponding matplotlib backend is used, otherwise it will be\n", " matplotlib's default (which you can set in your matplotlib\n", " config file).\n", " \n", " optional arguments:\n", " -l, --list Show available matplotlib backends\n", "%mkdir:\n", " Alias for `!mkdir`\n", "%more:\n", " Show a file through the pager.\n", " \n", " Files ending in .py are syntax-highlighted.\n", "%mv:\n", " Alias for `!mv`\n", "%notebook:\n", " ::\n", " \n", " %notebook filename\n", " \n", " Export and convert IPython notebooks.\n", " \n", " This function can export the current IPython history to a notebook file.\n", " For example, to export the history to \"foo.ipynb\" do \"%notebook foo.ipynb\".\n", " \n", " The -e or --export flag is deprecated in IPython 5.2, and will be\n", " removed in the future.\n", " \n", " positional arguments:\n", " filename Notebook name or filename\n", "%page:\n", " Pretty print the object and display it through a pager.\n", " \n", " %page [options] OBJECT\n", " \n", " If no object is given, use _ (last output).\n", " \n", " Options:\n", " \n", " -r: page str(object), don't pretty-print it.\n", "%pastebin:\n", " Upload code to dpaste's paste bin, returning the URL.\n", " \n", " Usage:\n", " %pastebin [-d \"Custom description\"] 1-7\n", " \n", " The argument can be an input history range, a filename, or the name of a\n", " string or macro.\n", " \n", " Options:\n", " \n", " -d: Pass a custom description for the gist. The default will say\n", " \"Pasted from IPython\".\n", "%pdb:\n", " Control the automatic calling of the pdb interactive debugger.\n", " \n", " Call as '%pdb on', '%pdb 1', '%pdb off' or '%pdb 0'. If called without\n", " argument it works as a toggle.\n", " \n", " When an exception is triggered, IPython can optionally call the\n", " interactive pdb debugger after the traceback printout. %pdb toggles\n", " this feature on and off.\n", " \n", " The initial state of this feature is set in your configuration\n", " file (the option is ``InteractiveShell.pdb``).\n", " \n", " If you want to just activate the debugger AFTER an exception has fired,\n", " without having to type '%pdb on' and rerunning your code, you can use\n", " the %debug magic.\n", "%pdef:\n", " Print the call signature for any callable object.\n", " \n", " If the object is a class, print the constructor information.\n", " \n", " Examples\n", " --------\n", " ::\n", " \n", " In [3]: %pdef urllib.urlopen\n", " urllib.urlopen(url, data=None, proxies=None)\n", "%pdoc:\n", " Print the docstring for an object.\n", " \n", " If the given object is a class, it will print both the class and the\n", " constructor docstrings.\n", "%pfile:\n", " Print (or run through pager) the file where an object is defined.\n", " \n", " The file opens at the line where the object definition begins. IPython\n", " will honor the environment variable PAGER if set, and otherwise will\n", " do its best to print the file in a convenient form.\n", " \n", " If the given argument is not an object currently defined, IPython will\n", " try to interpret it as a filename (automatically adding a .py extension\n", " if needed). You can thus use %pfile as a syntax highlighting code\n", " viewer.\n", "%pinfo:\n", " Provide detailed information about an object.\n", " \n", " '%pinfo object' is just a synonym for object? or ?object.\n", "%pinfo2:\n", " Provide extra detailed information about an object.\n", " \n", " '%pinfo2 object' is just a synonym for object?? or ??object.\n", "%pip:\n", " Run the pip package manager within the current kernel.\n", " \n", " Usage:\n", " %pip install [pkgs]\n", "%popd:\n", " Change to directory popped off the top of the stack.\n", "%pprint:\n", " Toggle pretty printing on/off.\n", "%precision:\n", " Set floating point precision for pretty printing.\n", " \n", " Can set either integer precision or a format string.\n", " \n", " If numpy has been imported and precision is an int,\n", " numpy display precision will also be set, via ``numpy.set_printoptions``.\n", " \n", " If no argument is given, defaults will be restored.\n", " \n", " Examples\n", " --------\n", " ::\n", " \n", " In [1]: from math import pi\n", " \n", " In [2]: %precision 3\n", " Out[2]: u'%.3f'\n", " \n", " In [3]: pi\n", " Out[3]: 3.142\n", " \n", " In [4]: %precision %i\n", " Out[4]: u'%i'\n", " \n", " In [5]: pi\n", " Out[5]: 3\n", " \n", " In [6]: %precision %e\n", " Out[6]: u'%e'\n", " \n", " In [7]: pi**10\n", " Out[7]: 9.364805e+04\n", " \n", " In [8]: %precision\n", " Out[8]: u'%r'\n", " \n", " In [9]: pi**10\n", " Out[9]: 93648.047476082982\n", "%prun:\n", " Run a statement through the python code profiler.\n", " \n", " Usage, in line mode:\n", " %prun [options] statement\n", " \n", " Usage, in cell mode:\n", " %%prun [options] [statement]\n", " code...\n", " code...\n", " \n", " In cell mode, the additional code lines are appended to the (possibly\n", " empty) statement in the first line. Cell mode allows you to easily\n", " profile multiline blocks without having to put them in a separate\n", " function.\n", " \n", " The given statement (which doesn't require quote marks) is run via the\n", " python profiler in a manner similar to the profile.run() function.\n", " Namespaces are internally managed to work correctly; profile.run\n", " cannot be used in IPython because it makes certain assumptions about\n", " namespaces which do not hold under IPython.\n", " \n", " Options:\n", " \n", " -l <limit>\n", " you can place restrictions on what or how much of the\n", " profile gets printed. The limit value can be:\n", " \n", " * A string: only information for function names containing this string\n", " is printed.\n", " \n", " * An integer: only these many lines are printed.\n", " \n", " * A float (between 0 and 1): this fraction of the report is printed\n", " (for example, use a limit of 0.4 to see the topmost 40% only).\n", " \n", " You can combine several limits with repeated use of the option. For\n", " example, ``-l __init__ -l 5`` will print only the topmost 5 lines of\n", " information about class constructors.\n", " \n", " -r\n", " return the pstats.Stats object generated by the profiling. This\n", " object has all the information about the profile in it, and you can\n", " later use it for further analysis or in other functions.\n", " \n", " -s <key>\n", " sort profile by given key. You can provide more than one key\n", " by using the option several times: '-s key1 -s key2 -s key3...'. The\n", " default sorting key is 'time'.\n", " \n", " The following is copied verbatim from the profile documentation\n", " referenced below:\n", " \n", " When more than one key is provided, additional keys are used as\n", " secondary criteria when the there is equality in all keys selected\n", " before them.\n", " \n", " Abbreviations can be used for any key names, as long as the\n", " abbreviation is unambiguous. The following are the keys currently\n", " defined:\n", " \n", " ============ =====================\n", " Valid Arg Meaning\n", " ============ =====================\n", " \"calls\" call count\n", " \"cumulative\" cumulative time\n", " \"file\" file name\n", " \"module\" file name\n", " \"pcalls\" primitive call count\n", " \"line\" line number\n", " \"name\" function name\n", " \"nfl\" name/file/line\n", " \"stdname\" standard name\n", " \"time\" internal time\n", " ============ =====================\n", " \n", " Note that all sorts on statistics are in descending order (placing\n", " most time consuming items first), where as name, file, and line number\n", " searches are in ascending order (i.e., alphabetical). The subtle\n", " distinction between \"nfl\" and \"stdname\" is that the standard name is a\n", " sort of the name as printed, which means that the embedded line\n", " numbers get compared in an odd way. For example, lines 3, 20, and 40\n", " would (if the file names were the same) appear in the string order\n", " \"20\" \"3\" and \"40\". In contrast, \"nfl\" does a numeric compare of the\n", " line numbers. In fact, sort_stats(\"nfl\") is the same as\n", " sort_stats(\"name\", \"file\", \"line\").\n", " \n", " -T <filename>\n", " save profile results as shown on screen to a text\n", " file. The profile is still shown on screen.\n", " \n", " -D <filename>\n", " save (via dump_stats) profile statistics to given\n", " filename. This data is in a format understood by the pstats module, and\n", " is generated by a call to the dump_stats() method of profile\n", " objects. The profile is still shown on screen.\n", " \n", " -q\n", " suppress output to the pager. Best used with -T and/or -D above.\n", " \n", " If you want to run complete programs under the profiler's control, use\n", " ``%run -p [prof_opts] filename.py [args to program]`` where prof_opts\n", " contains profiler specific options as described here.\n", " \n", " You can read the complete documentation for the profile module with::\n", " \n", " In [1]: import profile; profile.help()\n", " \n", " .. versionchanged:: 7.3\n", " User variables are no longer expanded,\n", " the magic line is always left unmodified.\n", "%psearch:\n", " Search for object in namespaces by wildcard.\n", " \n", " %psearch [options] PATTERN [OBJECT TYPE]\n", " \n", " Note: ? can be used as a synonym for %psearch, at the beginning or at\n", " the end: both a*? and ?a* are equivalent to '%psearch a*'. Still, the\n", " rest of the command line must be unchanged (options come first), so\n", " for example the following forms are equivalent\n", " \n", " %psearch -i a* function\n", " -i a* function?\n", " ?-i a* function\n", " \n", " Arguments:\n", " \n", " PATTERN\n", " \n", " where PATTERN is a string containing * as a wildcard similar to its\n", " use in a shell. The pattern is matched in all namespaces on the\n", " search path. By default objects starting with a single _ are not\n", " matched, many IPython generated objects have a single\n", " underscore. The default is case insensitive matching. Matching is\n", " also done on the attributes of objects and not only on the objects\n", " in a module.\n", " \n", " [OBJECT TYPE]\n", " \n", " Is the name of a python type from the types module. The name is\n", " given in lowercase without the ending type, ex. StringType is\n", " written string. By adding a type here only objects matching the\n", " given type are matched. Using all here makes the pattern match all\n", " types (this is the default).\n", " \n", " Options:\n", " \n", " -a: makes the pattern match even objects whose names start with a\n", " single underscore. These names are normally omitted from the\n", " search.\n", " \n", " -i/-c: make the pattern case insensitive/sensitive. If neither of\n", " these options are given, the default is read from your configuration\n", " file, with the option ``InteractiveShell.wildcards_case_sensitive``.\n", " If this option is not specified in your configuration file, IPython's\n", " internal default is to do a case sensitive search.\n", " \n", " -e/-s NAMESPACE: exclude/search a given namespace. The pattern you\n", " specify can be searched in any of the following namespaces:\n", " 'builtin', 'user', 'user_global','internal', 'alias', where\n", " 'builtin' and 'user' are the search defaults. Note that you should\n", " not use quotes when specifying namespaces.\n", " \n", " -l: List all available object types for object matching. This function\n", " can be used without arguments.\n", " \n", " 'Builtin' contains the python module builtin, 'user' contains all\n", " user data, 'alias' only contain the shell aliases and no python\n", " objects, 'internal' contains objects used by IPython. The\n", " 'user_global' namespace is only used by embedded IPython instances,\n", " and it contains module-level globals. You can add namespaces to the\n", " search with -s or exclude them with -e (these options can be given\n", " more than once).\n", " \n", " Examples\n", " --------\n", " ::\n", " \n", " %psearch a* -> objects beginning with an a\n", " %psearch -e builtin a* -> objects NOT in the builtin space starting in a\n", " %psearch a* function -> all functions beginning with an a\n", " %psearch re.e* -> objects beginning with an e in module re\n", " %psearch r*.e* -> objects that start with e in modules starting in r\n", " %psearch r*.* string -> all strings in modules beginning with r\n", " \n", " Case sensitive search::\n", " \n", " %psearch -c a* list all object beginning with lower case a\n", " \n", " Show objects beginning with a single _::\n", " \n", " %psearch -a _* list objects beginning with a single underscore\n", " \n", " List available objects::\n", " \n", " %psearch -l list all available object types\n", "%psource:\n", " Print (or run through pager) the source code for an object.\n", "%pushd:\n", " Place the current dir on stack and change directory.\n", " \n", " Usage:\n", " %pushd ['dirname']\n", "%pwd:\n", " Return the current working directory path.\n", " \n", " Examples\n", " --------\n", " ::\n", " \n", " In [9]: pwd\n", " Out[9]: '/home/tsuser/sprint/ipython'\n", "%pycat:\n", " Show a syntax-highlighted file through a pager.\n", " \n", " This magic is similar to the cat utility, but it will assume the file\n", " to be Python source and will show it with syntax highlighting.\n", " \n", " This magic command can either take a local filename, an url,\n", " an history range (see %history) or a macro as argument ::\n", " \n", " %pycat myscript.py\n", " %pycat 7-27\n", " %pycat myMacro\n", " %pycat http://www.example.com/myscript.py\n", "%pylab:\n", " ::\n", " \n", " %pylab [--no-import-all] [gui]\n", " \n", " Load numpy and matplotlib to work interactively.\n", " \n", " This function lets you activate pylab (matplotlib, numpy and\n", " interactive support) at any point during an IPython session.\n", " \n", " %pylab makes the following imports::\n", " \n", " import numpy\n", " import matplotlib\n", " from matplotlib import pylab, mlab, pyplot\n", " np = numpy\n", " plt = pyplot\n", " \n", " from IPython.display import display\n", " from IPython.core.pylabtools import figsize, getfigs\n", " \n", " from pylab import *\n", " from numpy import *\n", " \n", " If you pass `--no-import-all`, the last two `*` imports will be excluded.\n", " \n", " See the %matplotlib magic for more details about activating matplotlib\n", " without affecting the interactive namespace.\n", " \n", " positional arguments:\n", " gui Name of the matplotlib backend to use ('agg', 'gtk',\n", " 'gtk3', 'inline', 'ipympl', 'nbagg', 'notebook', 'osx',\n", " 'pdf', 'ps', 'qt', 'qt4', 'qt5', 'svg', 'tk', 'widget',\n", " 'wx'). If given, the corresponding matplotlib backend is\n", " used, otherwise it will be matplotlib's default (which you\n", " can set in your matplotlib config file).\n", " \n", " optional arguments:\n", " --no-import-all Prevent IPython from performing ``import *`` into the\n", " interactive namespace. You can govern the default behavior\n", " of this flag with the InteractiveShellApp.pylab_import_all\n", " configurable.\n", "%qtconsole:\n", " Open a qtconsole connected to this kernel.\n", " \n", " Useful for connecting a qtconsole to running notebooks, for better\n", " debugging.\n", "%quickref:\n", " Show a quick reference sheet\n", "%recall:\n", " Repeat a command, or get command to input line for editing.\n", " \n", " %recall and %rep are equivalent.\n", " \n", " - %recall (no arguments):\n", " \n", " Place a string version of last computation result (stored in the\n", " special '_' variable) to the next input prompt. Allows you to create\n", " elaborate command lines without using copy-paste::\n", " \n", " In[1]: l = [\"hei\", \"vaan\"]\n", " In[2]: \"\".join(l)\n", " Out[2]: heivaan\n", " In[3]: %recall\n", " In[4]: heivaan_ <== cursor blinking\n", " \n", " %recall 45\n", " \n", " Place history line 45 on the next input prompt. Use %hist to find\n", " out the number.\n", " \n", " %recall 1-4\n", " \n", " Combine the specified lines into one cell, and place it on the next\n", " input prompt. See %history for the slice syntax.\n", " \n", " %recall foo+bar\n", " \n", " If foo+bar can be evaluated in the user namespace, the result is\n", " placed at the next input prompt. Otherwise, the history is searched\n", " for lines which contain that substring, and the most recent one is\n", " placed at the next input prompt.\n", "%rehashx:\n", " Update the alias table with all executable files in $PATH.\n", " \n", " rehashx explicitly checks that every entry in $PATH is a file\n", " with execute access (os.X_OK).\n", " \n", " Under Windows, it checks executability as a match against a\n", " '|'-separated string of extensions, stored in the IPython config\n", " variable win_exec_ext. This defaults to 'exe|com|bat'.\n", " \n", " This function also resets the root module cache of module completer,\n", " used on slow filesystems.\n", "%reload_ext:\n", " Reload an IPython extension by its module name.\n", "%rep:\n", " Alias for `%recall`.\n", "%rerun:\n", " Re-run previous input\n", " \n", " By default, you can specify ranges of input history to be repeated\n", " (as with %history). With no arguments, it will repeat the last line.\n", " \n", " Options:\n", " \n", " -l <n> : Repeat the last n lines of input, not including the\n", " current command.\n", " \n", " -g foo : Repeat the most recent line which contains foo\n", "%reset:\n", " Resets the namespace by removing all names defined by the user, if\n", " called without arguments, or by removing some types of objects, such\n", " as everything currently in IPython's In[] and Out[] containers (see\n", " the parameters for details).\n", " \n", " Parameters\n", " ----------\n", " -f : force reset without asking for confirmation.\n", " \n", " -s : 'Soft' reset: Only clears your namespace, leaving history intact.\n", " References to objects may be kept. By default (without this option),\n", " we do a 'hard' reset, giving you a new session and removing all\n", " references to objects from the current session.\n", " \n", " in : reset input history\n", " \n", " out : reset output history\n", " \n", " dhist : reset directory history\n", " \n", " array : reset only variables that are NumPy arrays\n", " \n", " See Also\n", " --------\n", " reset_selective : invoked as ``%reset_selective``\n", " \n", " Examples\n", " --------\n", " ::\n", " \n", " In [6]: a = 1\n", " \n", " In [7]: a\n", " Out[7]: 1\n", " \n", " In [8]: 'a' in get_ipython().user_ns\n", " Out[8]: True\n", " \n", " In [9]: %reset -f\n", " \n", " In [1]: 'a' in get_ipython().user_ns\n", " Out[1]: False\n", " \n", " In [2]: %reset -f in\n", " Flushing input history\n", " \n", " In [3]: %reset -f dhist in\n", " Flushing directory history\n", " Flushing input history\n", " \n", " Notes\n", " -----\n", " Calling this magic from clients that do not implement standard input,\n", " such as the ipython notebook interface, will reset the namespace\n", " without confirmation.\n", "%reset_selective:\n", " Resets the namespace by removing names defined by the user.\n", " \n", " Input/Output history are left around in case you need them.\n", " \n", " %reset_selective [-f] regex\n", " \n", " No action is taken if regex is not included\n", " \n", " Options\n", " -f : force reset without asking for confirmation.\n", " \n", " See Also\n", " --------\n", " reset : invoked as ``%reset``\n", " \n", " Examples\n", " --------\n", " \n", " We first fully reset the namespace so your output looks identical to\n", " this example for pedagogical reasons; in practice you do not need a\n", " full reset::\n", " \n", " In [1]: %reset -f\n", " \n", " Now, with a clean namespace we can make a few variables and use\n", " ``%reset_selective`` to only delete names that match our regexp::\n", " \n", " In [2]: a=1; b=2; c=3; b1m=4; b2m=5; b3m=6; b4m=7; b2s=8\n", " \n", " In [3]: who_ls\n", " Out[3]: ['a', 'b', 'b1m', 'b2m', 'b2s', 'b3m', 'b4m', 'c']\n", " \n", " In [4]: %reset_selective -f b[2-3]m\n", " \n", " In [5]: who_ls\n", " Out[5]: ['a', 'b', 'b1m', 'b2s', 'b4m', 'c']\n", " \n", " In [6]: %reset_selective -f d\n", " \n", " In [7]: who_ls\n", " Out[7]: ['a', 'b', 'b1m', 'b2s', 'b4m', 'c']\n", " \n", " In [8]: %reset_selective -f c\n", " \n", " In [9]: who_ls\n", " Out[9]: ['a', 'b', 'b1m', 'b2s', 'b4m']\n", " \n", " In [10]: %reset_selective -f b\n", " \n", " In [11]: who_ls\n", " Out[11]: ['a']\n", " \n", " Notes\n", " -----\n", " Calling this magic from clients that do not implement standard input,\n", " such as the ipython notebook interface, will reset the namespace\n", " without confirmation.\n", "%rm:\n", " Alias for `!rm`\n", "%rmdir:\n", " Alias for `!rmdir`\n", "%run:\n", " Run the named file inside IPython as a program.\n", " \n", " Usage::\n", " \n", " %run [-n -i -e -G]\n", " [( -t [-N<N>] | -d [-b<N>] | -p [profile options] )]\n", " ( -m mod | file ) [args]\n", " \n", " Parameters after the filename are passed as command-line arguments to\n", " the program (put in sys.argv). Then, control returns to IPython's\n", " prompt.\n", " \n", " This is similar to running at a system prompt ``python file args``,\n", " but with the advantage of giving you IPython's tracebacks, and of\n", " loading all variables into your interactive namespace for further use\n", " (unless -p is used, see below).\n", " \n", " The file is executed in a namespace initially consisting only of\n", " ``__name__=='__main__'`` and sys.argv constructed as indicated. It thus\n", " sees its environment as if it were being run as a stand-alone program\n", " (except for sharing global objects such as previously imported\n", " modules). But after execution, the IPython interactive namespace gets\n", " updated with all variables defined in the program (except for __name__\n", " and sys.argv). This allows for very convenient loading of code for\n", " interactive work, while giving each program a 'clean sheet' to run in.\n", " \n", " Arguments are expanded using shell-like glob match. Patterns\n", " '*', '?', '[seq]' and '[!seq]' can be used. Additionally,\n", " tilde '~' will be expanded into user's home directory. Unlike\n", " real shells, quotation does not suppress expansions. Use\n", " *two* back slashes (e.g. ``\\\\*``) to suppress expansions.\n", " To completely disable these expansions, you can use -G flag.\n", " \n", " On Windows systems, the use of single quotes `'` when specifying \n", " a file is not supported. Use double quotes `\"`.\n", " \n", " Options:\n", " \n", " -n\n", " __name__ is NOT set to '__main__', but to the running file's name\n", " without extension (as python does under import). This allows running\n", " scripts and reloading the definitions in them without calling code\n", " protected by an ``if __name__ == \"__main__\"`` clause.\n", " \n", " -i\n", " run the file in IPython's namespace instead of an empty one. This\n", " is useful if you are experimenting with code written in a text editor\n", " which depends on variables defined interactively.\n", " \n", " -e\n", " ignore sys.exit() calls or SystemExit exceptions in the script\n", " being run. This is particularly useful if IPython is being used to\n", " run unittests, which always exit with a sys.exit() call. In such\n", " cases you are interested in the output of the test results, not in\n", " seeing a traceback of the unittest module.\n", " \n", " -t\n", " print timing information at the end of the run. IPython will give\n", " you an estimated CPU time consumption for your script, which under\n", " Unix uses the resource module to avoid the wraparound problems of\n", " time.clock(). Under Unix, an estimate of time spent on system tasks\n", " is also given (for Windows platforms this is reported as 0.0).\n", " \n", " If -t is given, an additional ``-N<N>`` option can be given, where <N>\n", " must be an integer indicating how many times you want the script to\n", " run. The final timing report will include total and per run results.\n", " \n", " For example (testing the script uniq_stable.py)::\n", " \n", " In [1]: run -t uniq_stable\n", " \n", " IPython CPU timings (estimated):\n", " User : 0.19597 s.\n", " System: 0.0 s.\n", " \n", " In [2]: run -t -N5 uniq_stable\n", " \n", " IPython CPU timings (estimated):\n", " Total runs performed: 5\n", " Times : Total Per run\n", " User : 0.910862 s, 0.1821724 s.\n", " System: 0.0 s, 0.0 s.\n", " \n", " -d\n", " run your program under the control of pdb, the Python debugger.\n", " This allows you to execute your program step by step, watch variables,\n", " etc. Internally, what IPython does is similar to calling::\n", " \n", " pdb.run('execfile(\"YOURFILENAME\")')\n", " \n", " with a breakpoint set on line 1 of your file. You can change the line\n", " number for this automatic breakpoint to be <N> by using the -bN option\n", " (where N must be an integer). For example::\n", " \n", " %run -d -b40 myscript\n", " \n", " will set the first breakpoint at line 40 in myscript.py. Note that\n", " the first breakpoint must be set on a line which actually does\n", " something (not a comment or docstring) for it to stop execution.\n", " \n", " Or you can specify a breakpoint in a different file::\n", " \n", " %run -d -b myotherfile.py:20 myscript\n", " \n", " When the pdb debugger starts, you will see a (Pdb) prompt. You must\n", " first enter 'c' (without quotes) to start execution up to the first\n", " breakpoint.\n", " \n", " Entering 'help' gives information about the use of the debugger. You\n", " can easily see pdb's full documentation with \"import pdb;pdb.help()\"\n", " at a prompt.\n", " \n", " -p\n", " run program under the control of the Python profiler module (which\n", " prints a detailed report of execution times, function calls, etc).\n", " \n", " You can pass other options after -p which affect the behavior of the\n", " profiler itself. See the docs for %prun for details.\n", " \n", " In this mode, the program's variables do NOT propagate back to the\n", " IPython interactive namespace (because they remain in the namespace\n", " where the profiler executes them).\n", " \n", " Internally this triggers a call to %prun, see its documentation for\n", " details on the options available specifically for profiling.\n", " \n", " There is one special usage for which the text above doesn't apply:\n", " if the filename ends with .ipy[nb], the file is run as ipython script,\n", " just as if the commands were written on IPython prompt.\n", " \n", " -m\n", " specify module name to load instead of script path. Similar to\n", " the -m option for the python interpreter. Use this option last if you\n", " want to combine with other %run options. Unlike the python interpreter\n", " only source modules are allowed no .pyc or .pyo files.\n", " For example::\n", " \n", " %run -m example\n", " \n", " will run the example module.\n", " \n", " -G\n", " disable shell-like glob expansion of arguments.\n", "%save:\n", " Save a set of lines or a macro to a given filename.\n", " \n", " Usage:\n", " %save [options] filename n1-n2 n3-n4 ... n5 .. n6 ...\n", " \n", " Options:\n", " \n", " -r: use 'raw' input. By default, the 'processed' history is used,\n", " so that magics are loaded in their transformed version to valid\n", " Python. If this option is given, the raw input as typed as the\n", " command line is used instead.\n", " \n", " -f: force overwrite. If file exists, %save will prompt for overwrite\n", " unless -f is given.\n", " \n", " -a: append to the file instead of overwriting it.\n", " \n", " This function uses the same syntax as %history for input ranges,\n", " then saves the lines to the filename you specify.\n", " \n", " It adds a '.py' extension to the file if you don't do so yourself, and\n", " it asks for confirmation before overwriting existing files.\n", " \n", " If `-r` option is used, the default extension is `.ipy`.\n", "%sc:\n", " Shell capture - run shell command and capture output (DEPRECATED use !).\n", " \n", " DEPRECATED. Suboptimal, retained for backwards compatibility.\n", " \n", " You should use the form 'var = !command' instead. Example:\n", " \n", " \"%sc -l myfiles = ls ~\" should now be written as\n", " \n", " \"myfiles = !ls ~\"\n", " \n", " myfiles.s, myfiles.l and myfiles.n still apply as documented\n", " below.\n", " \n", " --\n", " %sc [options] varname=command\n", " \n", " IPython will run the given command using commands.getoutput(), and\n", " will then update the user's interactive namespace with a variable\n", " called varname, containing the value of the call. Your command can\n", " contain shell wildcards, pipes, etc.\n", " \n", " The '=' sign in the syntax is mandatory, and the variable name you\n", " supply must follow Python's standard conventions for valid names.\n", " \n", " (A special format without variable name exists for internal use)\n", " \n", " Options:\n", " \n", " -l: list output. Split the output on newlines into a list before\n", " assigning it to the given variable. By default the output is stored\n", " as a single string.\n", " \n", " -v: verbose. Print the contents of the variable.\n", " \n", " In most cases you should not need to split as a list, because the\n", " returned value is a special type of string which can automatically\n", " provide its contents either as a list (split on newlines) or as a\n", " space-separated string. These are convenient, respectively, either\n", " for sequential processing or to be passed to a shell command.\n", " \n", " For example::\n", " \n", " # Capture into variable a\n", " In [1]: sc a=ls *py\n", " \n", " # a is a string with embedded newlines\n", " In [2]: a\n", " Out[2]: 'setup.py\\nwin32_manual_post_install.py'\n", " \n", " # which can be seen as a list:\n", " In [3]: a.l\n", " Out[3]: ['setup.py', 'win32_manual_post_install.py']\n", " \n", " # or as a whitespace-separated string:\n", " In [4]: a.s\n", " Out[4]: 'setup.py win32_manual_post_install.py'\n", " \n", " # a.s is useful to pass as a single command line:\n", " In [5]: !wc -l $a.s\n", " 146 setup.py\n", " 130 win32_manual_post_install.py\n", " 276 total\n", " \n", " # while the list form is useful to loop over:\n", " In [6]: for f in a.l:\n", " ...: !wc -l $f\n", " ...:\n", " 146 setup.py\n", " 130 win32_manual_post_install.py\n", " \n", " Similarly, the lists returned by the -l option are also special, in\n", " the sense that you can equally invoke the .s attribute on them to\n", " automatically get a whitespace-separated string from their contents::\n", " \n", " In [7]: sc -l b=ls *py\n", " \n", " In [8]: b\n", " Out[8]: ['setup.py', 'win32_manual_post_install.py']\n", " \n", " In [9]: b.s\n", " Out[9]: 'setup.py win32_manual_post_install.py'\n", " \n", " In summary, both the lists and strings used for output capture have\n", " the following special attributes::\n", " \n", " .l (or .list) : value as list.\n", " .n (or .nlstr): value as newline-separated string.\n", " .s (or .spstr): value as space-separated string.\n", "%set_env:\n", " Set environment variables. Assumptions are that either \"val\" is a\n", " name in the user namespace, or val is something that evaluates to a\n", " string.\n", " \n", " Usage:\n", " %set_env var val: set value for var\n", " %set_env var=val: set value for var\n", " %set_env var=$val: set value for var, using python expansion if possible\n", "%store:\n", " Lightweight persistence for python variables.\n", " \n", " Example::\n", " \n", " In [1]: l = ['hello',10,'world']\n", " In [2]: %store l\n", " In [3]: exit\n", " \n", " (IPython session is closed and started again...)\n", " \n", " ville@badger:~$ ipython\n", " In [1]: l\n", " NameError: name 'l' is not defined\n", " In [2]: %store -r\n", " In [3]: l\n", " Out[3]: ['hello', 10, 'world']\n", " \n", " Usage:\n", " \n", " * ``%store`` - Show list of all variables and their current\n", " values\n", " * ``%store spam`` - Store the *current* value of the variable spam\n", " to disk\n", " * ``%store -d spam`` - Remove the variable and its value from storage\n", " * ``%store -z`` - Remove all variables from storage\n", " * ``%store -r`` - Refresh all variables from store (overwrite\n", " current vals)\n", " * ``%store -r spam bar`` - Refresh specified variables from store\n", " (delete current val)\n", " * ``%store foo >a.txt`` - Store value of foo to new file a.txt\n", " * ``%store foo >>a.txt`` - Append value of foo to file a.txt\n", " \n", " It should be noted that if you change the value of a variable, you\n", " need to %store it again if you want to persist the new value.\n", " \n", " Note also that the variables will need to be pickleable; most basic\n", " python types can be safely %store'd.\n", " \n", " Also aliases can be %store'd across sessions.\n", " To remove an alias from the storage, use the %unalias magic.\n", "%sx:\n", " Shell execute - run shell command and capture output (!! is short-hand).\n", " \n", " %sx command\n", " \n", " IPython will run the given command using commands.getoutput(), and\n", " return the result formatted as a list (split on '\\n'). Since the\n", " output is _returned_, it will be stored in ipython's regular output\n", " cache Out[N] and in the '_N' automatic variables.\n", " \n", " Notes:\n", " \n", " 1) If an input line begins with '!!', then %sx is automatically\n", " invoked. That is, while::\n", " \n", " !ls\n", " \n", " causes ipython to simply issue system('ls'), typing::\n", " \n", " !!ls\n", " \n", " is a shorthand equivalent to::\n", " \n", " %sx ls\n", " \n", " 2) %sx differs from %sc in that %sx automatically splits into a list,\n", " like '%sc -l'. The reason for this is to make it as easy as possible\n", " to process line-oriented shell output via further python commands.\n", " %sc is meant to provide much finer control, but requires more\n", " typing.\n", " \n", " 3) Just like %sc -l, this is a list with special attributes:\n", " ::\n", " \n", " .l (or .list) : value as list.\n", " .n (or .nlstr): value as newline-separated string.\n", " .s (or .spstr): value as whitespace-separated string.\n", " \n", " This is very useful when trying to use such lists as arguments to\n", " system commands.\n", "%system:\n", " Shell execute - run shell command and capture output (!! is short-hand).\n", " \n", " %sx command\n", " \n", " IPython will run the given command using commands.getoutput(), and\n", " return the result formatted as a list (split on '\\n'). Since the\n", " output is _returned_, it will be stored in ipython's regular output\n", " cache Out[N] and in the '_N' automatic variables.\n", " \n", " Notes:\n", " \n", " 1) If an input line begins with '!!', then %sx is automatically\n", " invoked. That is, while::\n", " \n", " !ls\n", " \n", " causes ipython to simply issue system('ls'), typing::\n", " \n", " !!ls\n", " \n", " is a shorthand equivalent to::\n", " \n", " %sx ls\n", " \n", " 2) %sx differs from %sc in that %sx automatically splits into a list,\n", " like '%sc -l'. The reason for this is to make it as easy as possible\n", " to process line-oriented shell output via further python commands.\n", " %sc is meant to provide much finer control, but requires more\n", " typing.\n", " \n", " 3) Just like %sc -l, this is a list with special attributes:\n", " ::\n", " \n", " .l (or .list) : value as list.\n", " .n (or .nlstr): value as newline-separated string.\n", " .s (or .spstr): value as whitespace-separated string.\n", " \n", " This is very useful when trying to use such lists as arguments to\n", " system commands.\n", "%tb:\n", " Print the last traceback.\n", " \n", " Optionally, specify an exception reporting mode, tuning the\n", " verbosity of the traceback. By default the currently-active exception\n", " mode is used. See %xmode for changing exception reporting modes.\n", " \n", " Valid modes: Plain, Context, Verbose, and Minimal.\n", "%time:\n", " Time execution of a Python statement or expression.\n", " \n", " The CPU and wall clock times are printed, and the value of the\n", " expression (if any) is returned. Note that under Win32, system time\n", " is always reported as 0, since it can not be measured.\n", " \n", " This function can be used both as a line and cell magic:\n", " \n", " - In line mode you can time a single-line statement (though multiple\n", " ones can be chained with using semicolons).\n", " \n", " - In cell mode, you can time the cell body (a directly\n", " following statement raises an error).\n", " \n", " This function provides very basic timing functionality. Use the timeit\n", " magic for more control over the measurement.\n", " \n", " .. versionchanged:: 7.3\n", " User variables are no longer expanded,\n", " the magic line is always left unmodified.\n", " \n", " Examples\n", " --------\n", " ::\n", " \n", " In [1]: %time 2**128\n", " CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s\n", " Wall time: 0.00\n", " Out[1]: 340282366920938463463374607431768211456L\n", " \n", " In [2]: n = 1000000\n", " \n", " In [3]: %time sum(range(n))\n", " CPU times: user 1.20 s, sys: 0.05 s, total: 1.25 s\n", " Wall time: 1.37\n", " Out[3]: 499999500000L\n", " \n", " In [4]: %time print 'hello world'\n", " hello world\n", " CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s\n", " Wall time: 0.00\n", " \n", " Note that the time needed by Python to compile the given expression\n", " will be reported if it is more than 0.1s. In this example, the\n", " actual exponentiation is done by Python at compilation time, so while\n", " the expression can take a noticeable amount of time to compute, that\n", " time is purely due to the compilation:\n", " \n", " In [5]: %time 3**9999;\n", " CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s\n", " Wall time: 0.00 s\n", " \n", " In [6]: %time 3**999999;\n", " CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s\n", " Wall time: 0.00 s\n", " Compiler : 0.78 s\n", "%timeit:\n", " Time execution of a Python statement or expression\n", " \n", " Usage, in line mode:\n", " %timeit [-n<N> -r<R> [-t|-c] -q -p<P> -o] statement\n", " or in cell mode:\n", " %%timeit [-n<N> -r<R> [-t|-c] -q -p<P> -o] setup_code\n", " code\n", " code...\n", " \n", " Time execution of a Python statement or expression using the timeit\n", " module. This function can be used both as a line and cell magic:\n", " \n", " - In line mode you can time a single-line statement (though multiple\n", " ones can be chained with using semicolons).\n", " \n", " - In cell mode, the statement in the first line is used as setup code\n", " (executed but not timed) and the body of the cell is timed. The cell\n", " body has access to any variables created in the setup code.\n", " \n", " Options:\n", " -n<N>: execute the given statement <N> times in a loop. If <N> is not\n", " provided, <N> is determined so as to get sufficient accuracy.\n", " \n", " -r<R>: number of repeats <R>, each consisting of <N> loops, and take the\n", " best result.\n", " Default: 7\n", " \n", " -t: use time.time to measure the time, which is the default on Unix.\n", " This function measures wall time.\n", " \n", " -c: use time.clock to measure the time, which is the default on\n", " Windows and measures wall time. On Unix, resource.getrusage is used\n", " instead and returns the CPU user time.\n", " \n", " -p<P>: use a precision of <P> digits to display the timing result.\n", " Default: 3\n", " \n", " -q: Quiet, do not print result.\n", " \n", " -o: return a TimeitResult that can be stored in a variable to inspect\n", " the result in more details.\n", " \n", " .. versionchanged:: 7.3\n", " User variables are no longer expanded,\n", " the magic line is always left unmodified.\n", " \n", " Examples\n", " --------\n", " ::\n", " \n", " In [1]: %timeit pass\n", " 8.26 ns ± 0.12 ns per loop (mean ± std. dev. of 7 runs, 100000000 loops each)\n", " \n", " In [2]: u = None\n", " \n", " In [3]: %timeit u is None\n", " 29.9 ns ± 0.643 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)\n", " \n", " In [4]: %timeit -r 4 u == None\n", " \n", " In [5]: import time\n", " \n", " In [6]: %timeit -n1 time.sleep(2)\n", " \n", " \n", " The times reported by %timeit will be slightly higher than those\n", " reported by the timeit.py script when variables are accessed. This is\n", " due to the fact that %timeit executes the statement in the namespace\n", " of the shell, compared with timeit.py, which uses a single setup\n", " statement to import function or create variables. Generally, the bias\n", " does not matter as long as results from timeit.py are not mixed with\n", " those from %timeit.\n", "%unalias:\n", " Remove an alias\n", "%unload_ext:\n", " Unload an IPython extension by its module name.\n", " \n", " Not all extensions can be unloaded, only those which define an\n", " ``unload_ipython_extension`` function.\n", "%who:\n", " Print all interactive variables, with some minimal formatting.\n", " \n", " If any arguments are given, only variables whose type matches one of\n", " these are printed. For example::\n", " \n", " %who function str\n", " \n", " will only list functions and strings, excluding all other types of\n", " variables. To find the proper type names, simply use type(var) at a\n", " command line to see how python prints type names. For example:\n", " \n", " ::\n", " \n", " In [1]: type('hello')\n", " Out[1]: <type 'str'>\n", " \n", " indicates that the type name for strings is 'str'.\n", " \n", " ``%who`` always excludes executed names loaded through your configuration\n", " file and things which are internal to IPython.\n", " \n", " This is deliberate, as typically you may load many modules and the\n", " purpose of %who is to show you only what you've manually defined.\n", " \n", " Examples\n", " --------\n", " \n", " Define two variables and list them with who::\n", " \n", " In [1]: alpha = 123\n", " \n", " In [2]: beta = 'test'\n", " \n", " In [3]: %who\n", " alpha beta\n", " \n", " In [4]: %who int\n", " alpha\n", " \n", " In [5]: %who str\n", " beta\n", "%who_ls:\n", " Return a sorted list of all interactive variables.\n", " \n", " If arguments are given, only variables of types matching these\n", " arguments are returned.\n", " \n", " Examples\n", " --------\n", " \n", " Define two variables and list them with who_ls::\n", " \n", " In [1]: alpha = 123\n", " \n", " In [2]: beta = 'test'\n", " \n", " In [3]: %who_ls\n", " Out[3]: ['alpha', 'beta']\n", " \n", " In [4]: %who_ls int\n", " Out[4]: ['alpha']\n", " \n", " In [5]: %who_ls str\n", " Out[5]: ['beta']\n", "%whos:\n", " Like %who, but gives some extra information about each variable.\n", " \n", " The same type filtering of %who can be applied here.\n", " \n", " For all variables, the type is printed. Additionally it prints:\n", " \n", " - For {},[],(): their length.\n", " \n", " - For numpy arrays, a summary with shape, number of\n", " elements, typecode and size in memory.\n", " \n", " - Everything else: a string representation, snipping their middle if\n", " too long.\n", " \n", " Examples\n", " --------\n", " \n", " Define two variables and list them with whos::\n", " \n", " In [1]: alpha = 123\n", " \n", " In [2]: beta = 'test'\n", " \n", " In [3]: %whos\n", " Variable Type Data/Info\n", " --------------------------------\n", " alpha int 123\n", " beta str test\n", "%xdel:\n", " Delete a variable, trying to clear it from anywhere that\n", " IPython's machinery has references to it. By default, this uses\n", " the identity of the named object in the user namespace to remove\n", " references held under other names. The object is also removed\n", " from the output history.\n", " \n", " Options\n", " -n : Delete the specified name from all namespaces, without\n", " checking their identity.\n", "%xmode:\n", " Switch modes for the exception handlers.\n", " \n", " Valid modes: Plain, Context, Verbose, and Minimal.\n", " \n", " If called without arguments, acts as a toggle.\n", "%%!:\n", " Shell execute - run shell command and capture output (!! is short-hand).\n", " \n", " %sx command\n", " \n", " IPython will run the given command using commands.getoutput(), and\n", " return the result formatted as a list (split on '\\n'). Since the\n", " output is _returned_, it will be stored in ipython's regular output\n", " cache Out[N] and in the '_N' automatic variables.\n", " \n", " Notes:\n", " \n", " 1) If an input line begins with '!!', then %sx is automatically\n", " invoked. That is, while::\n", " \n", " !ls\n", " \n", " causes ipython to simply issue system('ls'), typing::\n", " \n", " !!ls\n", " \n", " is a shorthand equivalent to::\n", " \n", " %sx ls\n", " \n", " 2) %sx differs from %sc in that %sx automatically splits into a list,\n", " like '%sc -l'. The reason for this is to make it as easy as possible\n", " to process line-oriented shell output via further python commands.\n", " %sc is meant to provide much finer control, but requires more\n", " typing.\n", " \n", " 3) Just like %sc -l, this is a list with special attributes:\n", " ::\n", " \n", " .l (or .list) : value as list.\n", " .n (or .nlstr): value as newline-separated string.\n", " .s (or .spstr): value as whitespace-separated string.\n", " \n", " This is very useful when trying to use such lists as arguments to\n", " system commands.\n", "%%HTML:\n", " Alias for `%%html`.\n", "%%SVG:\n", " Alias for `%%svg`.\n", "%%bash:\n", " %%bash script magic\n", " \n", " Run cells with bash in a subprocess.\n", " \n", " This is a shortcut for `%%script bash`\n", "%%capture:\n", " ::\n", " \n", " %capture [--no-stderr] [--no-stdout] [--no-display] [output]\n", " \n", " run the cell, capturing stdout, stderr, and IPython's rich display() calls.\n", " \n", " positional arguments:\n", " output The name of the variable in which to store output. This is a\n", " utils.io.CapturedIO object with stdout/err attributes for the\n", " text of the captured output. CapturedOutput also has a show()\n", " method for displaying the output, and __call__ as well, so you\n", " can use that to quickly display the output. If unspecified,\n", " captured output is discarded.\n", " \n", " optional arguments:\n", " --no-stderr Don't capture stderr.\n", " --no-stdout Don't capture stdout.\n", " --no-display Don't capture IPython's rich display.\n", "%%debug:\n", " ::\n", " \n", " %debug [--breakpoint FILE:LINE] [statement [statement ...]]\n", " \n", " Activate the interactive debugger.\n", " \n", " This magic command support two ways of activating debugger.\n", " One is to activate debugger before executing code. This way, you\n", " can set a break point, to step through the code from the point.\n", " You can use this mode by giving statements to execute and optionally\n", " a breakpoint.\n", " \n", " The other one is to activate debugger in post-mortem mode. You can\n", " activate this mode simply running %debug without any argument.\n", " If an exception has just occurred, this lets you inspect its stack\n", " frames interactively. Note that this will always work only on the last\n", " traceback that occurred, so you must call this quickly after an\n", " exception that you wish to inspect has fired, because if another one\n", " occurs, it clobbers the previous one.\n", " \n", " If you want IPython to automatically do this on every exception, see\n", " the %pdb magic for more details.\n", " \n", " .. versionchanged:: 7.3\n", " When running code, user variables are no longer expanded,\n", " the magic line is always left unmodified.\n", " \n", " positional arguments:\n", " statement Code to run in debugger. You can omit this in cell\n", " magic mode.\n", " \n", " optional arguments:\n", " --breakpoint <FILE:LINE>, -b <FILE:LINE>\n", " Set break point at LINE in FILE.\n", "%%file:\n", " Alias for `%%writefile`.\n", "%%html:\n", " ::\n", " \n", " %html [--isolated]\n", " \n", " Render the cell as a block of HTML\n", " \n", " optional arguments:\n", " --isolated Annotate the cell as 'isolated'. Isolated cells are rendered\n", " inside their own <iframe> tag\n", "%%javascript:\n", " Run the cell block of Javascript code\n", "%%js:\n", " Run the cell block of Javascript code\n", " \n", " Alias of `%%javascript`\n", "%%latex:\n", " Render the cell as a block of latex\n", " \n", " The subset of latex which is support depends on the implementation in\n", " the client. In the Jupyter Notebook, this magic only renders the subset\n", " of latex defined by MathJax\n", " [here](https://docs.mathjax.org/en/v2.5-latest/tex.html).\n", "%%markdown:\n", " Render the cell as Markdown text block\n", "%%perl:\n", " %%perl script magic\n", " \n", " Run cells with perl in a subprocess.\n", " \n", " This is a shortcut for `%%script perl`\n", "%%prun:\n", " Run a statement through the python code profiler.\n", " \n", " Usage, in line mode:\n", " %prun [options] statement\n", " \n", " Usage, in cell mode:\n", " %%prun [options] [statement]\n", " code...\n", " code...\n", " \n", " In cell mode, the additional code lines are appended to the (possibly\n", " empty) statement in the first line. Cell mode allows you to easily\n", " profile multiline blocks without having to put them in a separate\n", " function.\n", " \n", " The given statement (which doesn't require quote marks) is run via the\n", " python profiler in a manner similar to the profile.run() function.\n", " Namespaces are internally managed to work correctly; profile.run\n", " cannot be used in IPython because it makes certain assumptions about\n", " namespaces which do not hold under IPython.\n", " \n", " Options:\n", " \n", " -l <limit>\n", " you can place restrictions on what or how much of the\n", " profile gets printed. The limit value can be:\n", " \n", " * A string: only information for function names containing this string\n", " is printed.\n", " \n", " * An integer: only these many lines are printed.\n", " \n", " * A float (between 0 and 1): this fraction of the report is printed\n", " (for example, use a limit of 0.4 to see the topmost 40% only).\n", " \n", " You can combine several limits with repeated use of the option. For\n", " example, ``-l __init__ -l 5`` will print only the topmost 5 lines of\n", " information about class constructors.\n", " \n", " -r\n", " return the pstats.Stats object generated by the profiling. This\n", " object has all the information about the profile in it, and you can\n", " later use it for further analysis or in other functions.\n", " \n", " -s <key>\n", " sort profile by given key. You can provide more than one key\n", " by using the option several times: '-s key1 -s key2 -s key3...'. The\n", " default sorting key is 'time'.\n", " \n", " The following is copied verbatim from the profile documentation\n", " referenced below:\n", " \n", " When more than one key is provided, additional keys are used as\n", " secondary criteria when the there is equality in all keys selected\n", " before them.\n", " \n", " Abbreviations can be used for any key names, as long as the\n", " abbreviation is unambiguous. The following are the keys currently\n", " defined:\n", " \n", " ============ =====================\n", " Valid Arg Meaning\n", " ============ =====================\n", " \"calls\" call count\n", " \"cumulative\" cumulative time\n", " \"file\" file name\n", " \"module\" file name\n", " \"pcalls\" primitive call count\n", " \"line\" line number\n", " \"name\" function name\n", " \"nfl\" name/file/line\n", " \"stdname\" standard name\n", " \"time\" internal time\n", " ============ =====================\n", " \n", " Note that all sorts on statistics are in descending order (placing\n", " most time consuming items first), where as name, file, and line number\n", " searches are in ascending order (i.e., alphabetical). The subtle\n", " distinction between \"nfl\" and \"stdname\" is that the standard name is a\n", " sort of the name as printed, which means that the embedded line\n", " numbers get compared in an odd way. For example, lines 3, 20, and 40\n", " would (if the file names were the same) appear in the string order\n", " \"20\" \"3\" and \"40\". In contrast, \"nfl\" does a numeric compare of the\n", " line numbers. In fact, sort_stats(\"nfl\") is the same as\n", " sort_stats(\"name\", \"file\", \"line\").\n", " \n", " -T <filename>\n", " save profile results as shown on screen to a text\n", " file. The profile is still shown on screen.\n", " \n", " -D <filename>\n", " save (via dump_stats) profile statistics to given\n", " filename. This data is in a format understood by the pstats module, and\n", " is generated by a call to the dump_stats() method of profile\n", " objects. The profile is still shown on screen.\n", " \n", " -q\n", " suppress output to the pager. Best used with -T and/or -D above.\n", " \n", " If you want to run complete programs under the profiler's control, use\n", " ``%run -p [prof_opts] filename.py [args to program]`` where prof_opts\n", " contains profiler specific options as described here.\n", " \n", " You can read the complete documentation for the profile module with::\n", " \n", " In [1]: import profile; profile.help()\n", " \n", " .. versionchanged:: 7.3\n", " User variables are no longer expanded,\n", " the magic line is always left unmodified.\n", "%%pypy:\n", " %%pypy script magic\n", " \n", " Run cells with pypy in a subprocess.\n", " \n", " This is a shortcut for `%%script pypy`\n", "%%python:\n", " %%python script magic\n", " \n", " Run cells with python in a subprocess.\n", " \n", " This is a shortcut for `%%script python`\n", "%%python2:\n", " %%python2 script magic\n", " \n", " Run cells with python2 in a subprocess.\n", " \n", " This is a shortcut for `%%script python2`\n", "%%python3:\n", " %%python3 script magic\n", " \n", " Run cells with python3 in a subprocess.\n", " \n", " This is a shortcut for `%%script python3`\n", "%%ruby:\n", " %%ruby script magic\n", " \n", " Run cells with ruby in a subprocess.\n", " \n", " This is a shortcut for `%%script ruby`\n", "%%script:\n", " ::\n", " \n", " %shebang [--no-raise-error] [--proc PROC] [--bg] [--err ERR] [--out OUT]\n", " \n", " Run a cell via a shell command\n", " \n", " The `%%script` line is like the #! line of script,\n", " specifying a program (bash, perl, ruby, etc.) with which to run.\n", " \n", " The rest of the cell is run by that program.\n", " \n", " Examples\n", " --------\n", " ::\n", " \n", " In [1]: %%script bash\n", " ...: for i in 1 2 3; do\n", " ...: echo $i\n", " ...: done\n", " 1\n", " 2\n", " 3\n", " \n", " optional arguments:\n", " --no-raise-error Whether you should raise an error message in addition to a\n", " stream on stderr if you get a nonzero exit code.\n", " --proc PROC The variable in which to store Popen instance. This is\n", " used only when --bg option is given.\n", " --bg Whether to run the script in the background. If given, the\n", " only way to see the output of the command is with\n", " --out/err.\n", " --err ERR The variable in which to store stderr from the script. If\n", " the script is backgrounded, this will be the stderr\n", " *pipe*, instead of the stderr text itself and will not be\n", " autoclosed.\n", " --out OUT The variable in which to store stdout from the script. If\n", " the script is backgrounded, this will be the stdout\n", " *pipe*, instead of the stderr text itself and will not be\n", " auto closed.\n", "%%sh:\n", " %%sh script magic\n", " \n", " Run cells with sh in a subprocess.\n", " \n", " This is a shortcut for `%%script sh`\n", "%%svg:\n", " Render the cell as an SVG literal\n", "%%sx:\n", " Shell execute - run shell command and capture output (!! is short-hand).\n", " \n", " %sx command\n", " \n", " IPython will run the given command using commands.getoutput(), and\n", " return the result formatted as a list (split on '\\n'). Since the\n", " output is _returned_, it will be stored in ipython's regular output\n", " cache Out[N] and in the '_N' automatic variables.\n", " \n", " Notes:\n", " \n", " 1) If an input line begins with '!!', then %sx is automatically\n", " invoked. That is, while::\n", " \n", " !ls\n", " \n", " causes ipython to simply issue system('ls'), typing::\n", " \n", " !!ls\n", " \n", " is a shorthand equivalent to::\n", " \n", " %sx ls\n", " \n", " 2) %sx differs from %sc in that %sx automatically splits into a list,\n", " like '%sc -l'. The reason for this is to make it as easy as possible\n", " to process line-oriented shell output via further python commands.\n", " %sc is meant to provide much finer control, but requires more\n", " typing.\n", " \n", " 3) Just like %sc -l, this is a list with special attributes:\n", " ::\n", " \n", " .l (or .list) : value as list.\n", " .n (or .nlstr): value as newline-separated string.\n", " .s (or .spstr): value as whitespace-separated string.\n", " \n", " This is very useful when trying to use such lists as arguments to\n", " system commands.\n", "%%system:\n", " Shell execute - run shell command and capture output (!! is short-hand).\n", " \n", " %sx command\n", " \n", " IPython will run the given command using commands.getoutput(), and\n", " return the result formatted as a list (split on '\\n'). Since the\n", " output is _returned_, it will be stored in ipython's regular output\n", " cache Out[N] and in the '_N' automatic variables.\n", " \n", " Notes:\n", " \n", " 1) If an input line begins with '!!', then %sx is automatically\n", " invoked. That is, while::\n", " \n", " !ls\n", " \n", " causes ipython to simply issue system('ls'), typing::\n", " \n", " !!ls\n", " \n", " is a shorthand equivalent to::\n", " \n", " %sx ls\n", " \n", " 2) %sx differs from %sc in that %sx automatically splits into a list,\n", " like '%sc -l'. The reason for this is to make it as easy as possible\n", " to process line-oriented shell output via further python commands.\n", " %sc is meant to provide much finer control, but requires more\n", " typing.\n", " \n", " 3) Just like %sc -l, this is a list with special attributes:\n", " ::\n", " \n", " .l (or .list) : value as list.\n", " .n (or .nlstr): value as newline-separated string.\n", " .s (or .spstr): value as whitespace-separated string.\n", " \n", " This is very useful when trying to use such lists as arguments to\n", " system commands.\n", "%%time:\n", " Time execution of a Python statement or expression.\n", " \n", " The CPU and wall clock times are printed, and the value of the\n", " expression (if any) is returned. Note that under Win32, system time\n", " is always reported as 0, since it can not be measured.\n", " \n", " This function can be used both as a line and cell magic:\n", " \n", " - In line mode you can time a single-line statement (though multiple\n", " ones can be chained with using semicolons).\n", " \n", " - In cell mode, you can time the cell body (a directly\n", " following statement raises an error).\n", " \n", " This function provides very basic timing functionality. Use the timeit\n", " magic for more control over the measurement.\n", " \n", " .. versionchanged:: 7.3\n", " User variables are no longer expanded,\n", " the magic line is always left unmodified.\n", " \n", " Examples\n", " --------\n", " ::\n", " \n", " In [1]: %time 2**128\n", " CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s\n", " Wall time: 0.00\n", " Out[1]: 340282366920938463463374607431768211456L\n", " \n", " In [2]: n = 1000000\n", " \n", " In [3]: %time sum(range(n))\n", " CPU times: user 1.20 s, sys: 0.05 s, total: 1.25 s\n", " Wall time: 1.37\n", " Out[3]: 499999500000L\n", " \n", " In [4]: %time print 'hello world'\n", " hello world\n", " CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s\n", " Wall time: 0.00\n", " \n", " Note that the time needed by Python to compile the given expression\n", " will be reported if it is more than 0.1s. In this example, the\n", " actual exponentiation is done by Python at compilation time, so while\n", " the expression can take a noticeable amount of time to compute, that\n", " time is purely due to the compilation:\n", " \n", " In [5]: %time 3**9999;\n", " CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s\n", " Wall time: 0.00 s\n", " \n", " In [6]: %time 3**999999;\n", " CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s\n", " Wall time: 0.00 s\n", " Compiler : 0.78 s\n", "%%timeit:\n", " Time execution of a Python statement or expression\n", " \n", " Usage, in line mode:\n", " %timeit [-n<N> -r<R> [-t|-c] -q -p<P> -o] statement\n", " or in cell mode:\n", " %%timeit [-n<N> -r<R> [-t|-c] -q -p<P> -o] setup_code\n", " code\n", " code...\n", " \n", " Time execution of a Python statement or expression using the timeit\n", " module. This function can be used both as a line and cell magic:\n", " \n", " - In line mode you can time a single-line statement (though multiple\n", " ones can be chained with using semicolons).\n", " \n", " - In cell mode, the statement in the first line is used as setup code\n", " (executed but not timed) and the body of the cell is timed. The cell\n", " body has access to any variables created in the setup code.\n", " \n", " Options:\n", " -n<N>: execute the given statement <N> times in a loop. If <N> is not\n", " provided, <N> is determined so as to get sufficient accuracy.\n", " \n", " -r<R>: number of repeats <R>, each consisting of <N> loops, and take the\n", " best result.\n", " Default: 7\n", " \n", " -t: use time.time to measure the time, which is the default on Unix.\n", " This function measures wall time.\n", " \n", " -c: use time.clock to measure the time, which is the default on\n", " Windows and measures wall time. On Unix, resource.getrusage is used\n", " instead and returns the CPU user time.\n", " \n", " -p<P>: use a precision of <P> digits to display the timing result.\n", " Default: 3\n", " \n", " -q: Quiet, do not print result.\n", " \n", " -o: return a TimeitResult that can be stored in a variable to inspect\n", " the result in more details.\n", " \n", " .. versionchanged:: 7.3\n", " User variables are no longer expanded,\n", " the magic line is always left unmodified.\n", " \n", " Examples\n", " --------\n", " ::\n", " \n", " In [1]: %timeit pass\n", " 8.26 ns ± 0.12 ns per loop (mean ± std. dev. of 7 runs, 100000000 loops each)\n", " \n", " In [2]: u = None\n", " \n", " In [3]: %timeit u is None\n", " 29.9 ns ± 0.643 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)\n", " \n", " In [4]: %timeit -r 4 u == None\n", " \n", " In [5]: import time\n", " \n", " In [6]: %timeit -n1 time.sleep(2)\n", " \n", " \n", " The times reported by %timeit will be slightly higher than those\n", " reported by the timeit.py script when variables are accessed. This is\n", " due to the fact that %timeit executes the statement in the namespace\n", " of the shell, compared with timeit.py, which uses a single setup\n", " statement to import function or create variables. Generally, the bias\n", " does not matter as long as results from timeit.py are not mixed with\n", " those from %timeit.\n", "%%writefile:\n", " ::\n", " \n", " %writefile [-a] filename\n", " \n", " Write the contents of the cell to a file.\n", " \n", " The file will be overwritten unless the -a (--append) flag is specified.\n", " \n", " positional arguments:\n", " filename file to write\n", " \n", " optional arguments:\n", " -a, --append Append contents of the cell to an existing file. The file will\n", " be created if it does not exist.\n", "\n", "Summary of magic functions (from %lsmagic):\n", "Available line magics:\n", "%alias %alias_magic %autoawait %autocall %automagic %autosave %bookmark %cat %cd %clear %colors %conda %config %connect_info %cp %debug %dhist %dirs %doctest_mode %ed %edit %env %gui %hist %history %killbgscripts %ldir %less %lf %lk %ll %load %load_ext %loadpy %logoff %logon %logstart %logstate %logstop %ls %lsmagic %lx %macro %magic %man %matplotlib %mkdir %more %mv %notebook %page %pastebin %pdb %pdef %pdoc %pfile %pinfo %pinfo2 %pip %popd %pprint %precision %prun %psearch %psource %pushd %pwd %pycat %pylab %qtconsole %quickref %recall %rehashx %reload_ext %rep %rerun %reset %reset_selective %rm %rmdir %run %save %sc %set_env %store %sx %system %tb %time %timeit %unalias %unload_ext %who %who_ls %whos %xdel %xmode\n", "\n", "Available cell magics:\n", "%%! %%HTML %%SVG %%bash %%capture %%debug %%file %%html %%javascript %%js %%latex %%markdown %%perl %%prun %%pypy %%python %%python2 %%python3 %%ruby %%script %%sh %%svg %%sx %%system %%time %%timeit %%writefile\n", "\n", "Automagic is ON, % prefix IS NOT needed for line magics." ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%magic" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Line vs cell magics:" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "16.9 µs ± 1.35 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)\n" ] } ], "source": [ "%timeit list(range(1000))" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1.86 µs ± 144 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)\n" ] } ], "source": [ "%%timeit\n", "list(range(10))\n", "list(range(100))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Line magics can be used even inside code blocks:" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "size: 100 1.24 µs ± 90.6 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)\n", "size: 200 1.73 µs ± 115 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)\n", "size: 300 3.22 µs ± 349 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)\n", "size: 400 5.16 µs ± 324 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)\n" ] } ], "source": [ "for i in range(1, 5):\n", " size = i*100\n", " print('size:', size, end=' ')\n", " %timeit list(range(size))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Magics can do anything they want with their input, so it doesn't have to be valid Python:" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "My shell is: /bin/bash\n", "My disk usage is:\n", "Filesystem Size Used Avail Use% Mounted on\n", "/dev/mapper/centos-root 47G 4.2G 40G 10% /\n", "devtmpfs 252G 0 252G 0% /dev\n", "tmpfs 252G 29G 223G 12% /dev/shm\n", "tmpfs 252G 1.4G 251G 1% /run\n", "tmpfs 252G 0 252G 0% /sys/fs/cgroup\n", "/dev/sda3 469M 177M 257M 41% /boot\n", "/dev/sda2 201M 12M 189M 6% /boot/efi\n", "/dev/mapper/centos-var 23G 5.4G 17G 25% /var\n", "/dev/mapper/centos-scratch 97G 60M 92G 1% /scratch\n", "/dev/mapper/centos-tmp 23G 11G 11G 51% /tmp\n", "direct 2.8T 1.1T 1.8T 37% /gpfs/direct\n", "arch 1.1P 538T 487T 53% /arch\n", "arch2 781T 755T 27T 97% /arch2\n", "fastdata 9.1P 6.0P 3.1P 66% /p/fastdata\n", "home 61T 6.7T 54T 11% /p/home\n", "hpcmon 17T 3.8T 13T 24% /p/hpcmon\n", "jureca_usr_local 17T 4.0T 13T 25% /gpfs/usrlocal\n", "jurecabooster_usr_local 2.1T 411G 1.7T 20% /p/software/jurecabooster\n", "project 3.8P 2.1P 1.7P 56% /p/project\n", "scratch 9.1P 4.8P 4.3P 54% /p/scratch\n", "usersoftware 33T 21G 33T 1% /p/usersoftware\n", "tmpfs 51G 4.0K 51G 1% /run/user/14033\n", "tmpfs 51G 4.0K 51G 1% /run/user/12885\n", "tmpfs 51G 4.0K 51G 1% /run/user/14576\n", "tmpfs 51G 4.0K 51G 1% /run/user/2763\n", "tmpfs 51G 4.0K 51G 1% /run/user/14500\n", "tmpfs 51G 0 51G 0% /run/user/5775\n", "tmpfs 51G 4.0K 51G 1% /run/user/6923\n", "tmpfs 51G 4.0K 51G 1% /run/user/16475\n", "largedata 18P 5.7P 13P 32% /p/largedata\n", "tmpfs 51G 4.0K 51G 1% /run/user/13728\n" ] } ], "source": [ "%%bash\n", "echo \"My shell is:\" $SHELL\n", "echo \"My disk usage is:\"\n", "df -h" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Another interesting cell magic: create any file you want locally from the notebook:" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Overwriting test.txt\n" ] } ], "source": [ "%%writefile test.txt\n", "This is a test file!\n", "It can contain anything I want...\n", "\n", "And more..." ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "This is a test file!\n", "It can contain anything I want...\n", "\n", "And more...\n" ] } ], "source": [ "!cat test.txt" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's see what other magics are currently defined in the system:" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "data": { "application/json": { "cell": { "!": "OSMagics", "HTML": "Other", "SVG": "Other", "bash": "Other", "capture": "ExecutionMagics", "debug": "ExecutionMagics", "file": "Other", "html": "DisplayMagics", "javascript": "DisplayMagics", "js": "DisplayMagics", "latex": "DisplayMagics", "markdown": "DisplayMagics", "perl": "Other", "prun": "ExecutionMagics", "pypy": "Other", "python": "Other", "python2": "Other", "python3": "Other", "ruby": "Other", "script": "ScriptMagics", "sh": "Other", "svg": "DisplayMagics", "sx": "OSMagics", "system": "OSMagics", "time": "ExecutionMagics", "timeit": "ExecutionMagics", "writefile": "OSMagics" }, "line": { "alias": "OSMagics", "alias_magic": "BasicMagics", "autoawait": "AsyncMagics", "autocall": "AutoMagics", "automagic": "AutoMagics", "autosave": "KernelMagics", "bookmark": "OSMagics", "cat": "Other", "cd": "OSMagics", "clear": "KernelMagics", "colors": "BasicMagics", "conda": "PackagingMagics", "config": "ConfigMagics", "connect_info": "KernelMagics", "cp": "Other", "debug": "ExecutionMagics", "dhist": "OSMagics", "dirs": "OSMagics", "doctest_mode": "BasicMagics", "ed": "Other", "edit": "KernelMagics", "env": "OSMagics", "gui": "BasicMagics", "hist": "Other", "history": "HistoryMagics", "killbgscripts": "ScriptMagics", "ldir": "Other", "less": "KernelMagics", "lf": "Other", "lk": "Other", "ll": "Other", "load": "CodeMagics", "load_ext": "ExtensionMagics", "loadpy": "CodeMagics", "logoff": "LoggingMagics", "logon": "LoggingMagics", "logstart": "LoggingMagics", "logstate": "LoggingMagics", "logstop": "LoggingMagics", "ls": "Other", "lsmagic": "BasicMagics", "lx": "Other", "macro": "ExecutionMagics", "magic": "BasicMagics", "man": "KernelMagics", "matplotlib": "PylabMagics", "mkdir": "Other", "more": "KernelMagics", "mv": "Other", "notebook": "BasicMagics", "page": "BasicMagics", "pastebin": "CodeMagics", "pdb": "ExecutionMagics", "pdef": "NamespaceMagics", "pdoc": "NamespaceMagics", "pfile": "NamespaceMagics", "pinfo": "NamespaceMagics", "pinfo2": "NamespaceMagics", "pip": "PackagingMagics", "popd": "OSMagics", "pprint": "BasicMagics", "precision": "BasicMagics", "prun": "ExecutionMagics", "psearch": "NamespaceMagics", "psource": "NamespaceMagics", "pushd": "OSMagics", "pwd": "OSMagics", "pycat": "OSMagics", "pylab": "PylabMagics", "qtconsole": "KernelMagics", "quickref": "BasicMagics", "recall": "HistoryMagics", "rehashx": "OSMagics", "reload_ext": "ExtensionMagics", "rep": "Other", "rerun": "HistoryMagics", "reset": "NamespaceMagics", "reset_selective": "NamespaceMagics", "rm": "Other", "rmdir": "Other", "run": "ExecutionMagics", "save": "CodeMagics", "sc": "OSMagics", "set_env": "OSMagics", "store": "StoreMagics", "sx": "OSMagics", "system": "OSMagics", "tb": "ExecutionMagics", "time": "ExecutionMagics", "timeit": "ExecutionMagics", "unalias": "OSMagics", "unload_ext": "ExtensionMagics", "who": "NamespaceMagics", "who_ls": "NamespaceMagics", "whos": "NamespaceMagics", "xdel": "NamespaceMagics", "xmode": "BasicMagics" } }, "text/plain": [ "Available line magics:\n", "%alias %alias_magic %autoawait %autocall %automagic %autosave %bookmark %cat %cd %clear %colors %conda %config %connect_info %cp %debug %dhist %dirs %doctest_mode %ed %edit %env %gui %hist %history %killbgscripts %ldir %less %lf %lk %ll %load %load_ext %loadpy %logoff %logon %logstart %logstate %logstop %ls %lsmagic %lx %macro %magic %man %matplotlib %mkdir %more %mv %notebook %page %pastebin %pdb %pdef %pdoc %pfile %pinfo %pinfo2 %pip %popd %pprint %precision %prun %psearch %psource %pushd %pwd %pycat %pylab %qtconsole %quickref %recall %rehashx %reload_ext %rep %rerun %reset %reset_selective %rm %rmdir %run %save %sc %set_env %store %sx %system %tb %time %timeit %unalias %unload_ext %who %who_ls %whos %xdel %xmode\n", "\n", "Available cell magics:\n", "%%! %%HTML %%SVG %%bash %%capture %%debug %%file %%html %%javascript %%js %%latex %%markdown %%perl %%prun %%pypy %%python %%python2 %%python3 %%ruby %%script %%sh %%svg %%sx %%system %%time %%timeit %%writefile\n", "\n", "Automagic is ON, % prefix IS NOT needed for line magics." ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "%lsmagic" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Running normal Python code: execution and errors" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Not only can you input normal Python code, you can even paste straight from a Python or IPython shell session:" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1\n", "1\n", "2\n", "3\n", "5\n", "8\n" ] } ], "source": [ ">>> # Fibonacci series:\n", "... # the sum of two elements defines the next\n", "... a, b = 0, 1\n", ">>> while b < 10:\n", "... print(b)\n", "... a, b = b, a+b" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0 1 2 3 4 5 6 7 8 9 " ] } ], "source": [ "In [1]: for i in range(10):\n", " ...: print(i, end=' ')\n", " ...: " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And when your code produces errors, you can control how they are displayed with the `%xmode` magic:" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Overwriting mod.py\n" ] } ], "source": [ "%%writefile mod.py\n", "\n", "def f(x):\n", " return 1.0/(x-1)\n", "\n", "def g(y):\n", " return f(y+1)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now let's call the function `g` with an argument that would produce an error:" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [], "source": [ "import mod\n", "#mod.g(0)" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Exception reporting mode: Plain\n" ] } ], "source": [ "%xmode plain\n", "#mod.g(0)" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Exception reporting mode: Verbose\n" ] } ], "source": [ "%xmode verbose\n", "#mod.g(0)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The default `%xmode` is \"context\", which shows additional context but not all local variables. Let's restore that one for the rest of our session." ] }, { "cell_type": "code", "execution_count": 35, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Exception reporting mode: Context\n" ] } ], "source": [ "%xmode context" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Running code with %run" ] }, { "cell_type": "code", "execution_count": 36, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Overwriting script.py\n" ] } ], "source": [ "%%writefile script.py\n", "x = 10\n", "y = 20\n", "z = x+y\n", "print('z is: %s' % z)" ] }, { "cell_type": "code", "execution_count": 37, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "z is: 30\n" ] } ], "source": [ "%run script" ] }, { "cell_type": "code", "execution_count": 38, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "10" ] }, "execution_count": 38, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Running code in other languages with special `%%` magics" ] }, { "cell_type": "code", "execution_count": 39, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "July" ] } ], "source": [ "%%perl\n", "@months = (\"July\", \"August\", \"September\");\n", "print $months[0];" ] }, { "cell_type": "code", "execution_count": 40, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Couldn't find program: 'ruby'\n" ] } ], "source": [ "%%ruby\n", "name = \"world\"\n", "puts \"Hello #{name.capitalize}!\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Raw Input in the notebook" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Since 1.0 the IPython notebook web application support `raw_input` which for example allow us to invoke the `%debug` magic in the notebook:" ] }, { "cell_type": "code", "execution_count": 41, "metadata": {}, "outputs": [], "source": [ "#mod.g(0)" ] }, { "cell_type": "code", "execution_count": 42, "metadata": {}, "outputs": [], "source": [ "#%debug" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Don't foget to exit your debugging session. Raw input can of course be use to ask for user input:" ] }, { "cell_type": "code", "execution_count": 44, "metadata": {}, "outputs": [], "source": [ "#enjoy = input('Are you enjoying this tutorial? ')\n", "#print('enjoy is:', enjoy)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Plotting in the notebook" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This magic configures matplotlib to render its figures inline:" ] }, { "cell_type": "code", "execution_count": 45, "metadata": {}, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "code", "execution_count": 46, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import matplotlib.pyplot as plt" ] }, { "cell_type": "code", "execution_count": 47, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYYAAAEICAYAAABbOlNNAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAIABJREFUeJzsvXmUXGd55/99at97qV7Uai0tyZJseZHAsg0xEIyxY5sJhpMAdjaSSeLjCeSXlRl+yW8SzoQ5h8lMEk4SAjGBQEICOCzBAbMYT8BbbEsGy5Yta2st3epW77XvVe/v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GFSNAE4Bfwp6s5bIWlw6FBXSqfCoGs8FqtPezcKSUOA9cBTZnYudJ5UmNklM5tOYu3ymZJi06UnaSFQZ2bbQ2fppllmNgN4EHg86mKNi37ADOB5M7sTaAT63HhnOhWGWqCg1X4+cCxQlrQV9c2vB1ab2Suh83RV1PzfBMwPHCUVs4BFUR/9WuB+SX8JGyl1ZnYs+l4HvEqimzguaoHaVi3NdSQKRZ+SToXhI6BY0vhowOcRYEPgTGklGrxdCVSa2XOh86RK0i2ShkXbA4G5wL6wqTrPzH5mZvlmNo7Ev/93zOzRwLFSImlwNHGBqAvmASA2s/TM7ARQI2ly9NAcoM9NvugXOkBvMbOLkp4ANgKZwEtmtidwrJRIWgPcB4yUVAv8wsxWhk2VklnAEmBX1E8P8HMzeyNgplTkAauiGW4ZwMtmFsspnzGWC7ya+IxBP+CvZvZW2EgpWw6sjj6gVgOPBc5zlbSZruqcc65z0qkryTnnXCd4YXDOOZfEC4NzzrkkXhicc84l8cLgnHMuiRcG55xzSbwwOOecS/I/07x8dXYH7RQAAAAASUVORK5CYII=\n", "text/plain": [ "<Figure size 432x288 with 1 Axes>" ] }, "metadata": { "needs_background": "light" }, "output_type": "display_data" } ], "source": [ "x = np.linspace(0, 2*np.pi, 300)\n", "y = np.sin(x**2)\n", "plt.plot(x, y)\n", "plt.title(\"A little chirp\")\n", "fig = plt.gcf() # let's keep the figure object around for later..." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## The IPython kernel/client model" ] }, { "cell_type": "code", "execution_count": 48, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{\n", " \"shell_port\": 34542,\n", " \"iopub_port\": 50306,\n", " \"stdin_port\": 53523,\n", " \"control_port\": 52597,\n", " \"hb_port\": 40690,\n", " \"ip\": \"127.0.0.1\",\n", " \"key\": \"d097912e-27ed0f503f8c2b012e03b09d\",\n", " \"transport\": \"tcp\",\n", " \"signature_scheme\": \"hmac-sha256\",\n", " \"kernel_name\": \"\"\n", "}\n", "\n", "Paste the above JSON into a file, and connect with:\n", " $> jupyter <app> --existing <file>\n", "or, if you are local, you can connect with just:\n", " $> jupyter <app> --existing kernel-5f69233d-bd10-4fcb-aeca-c131ac5d3116.json\n", "or even just:\n", " $> jupyter <app> --existing\n", "if this is the most recent Jupyter kernel you have started.\n" ] } ], "source": [ "%connect_info" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can connect automatically a Qt Console to the currently running kernel with the `%qtconsole` magic, or by typing `ipython console --existing <kernel-UUID>` in any terminal:" ] }, { "cell_type": "code", "execution_count": 49, "metadata": {}, "outputs": [], "source": [ "#%qtconsole" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Cleanup" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "!rm -f test.txt\n", "!rm -f mod.py\n", "!rm -f script.py" ] } ], "metadata": { "hide_input": false, "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.8" } }, "nbformat": 4, "nbformat_minor": 4 }