diff --git a/.github/workflows/embed-code-in-markdowns.yml b/.github/workflows/embed-code-in-markdowns.yml new file mode 100644 index 0000000..5c88b3d --- /dev/null +++ b/.github/workflows/embed-code-in-markdowns.yml @@ -0,0 +1,17 @@ +name: Looping over values in Github Actions + +on: + push: + +jobs: + embed-code: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + # - name: Collect Markdowns + # id: collect-markdowns + # run: | + # files=$(find -name '*.md' -print) + # echo "{MARKDOWN_FILES}=($files)" >> $GITHUB_ENV diff --git a/.gitignore b/.gitignore index 117328a..a689dcf 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,8 @@ __pycache__ *.sublime-build *.pyc **/venv + +*env* +*_build* +*_static* +*_templates* \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..6f970d9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,82 @@ +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + +"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. + +"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. + +2. Grant of Copyright License. + +Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. + +Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. + +4. Redistribution. + +You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: + + You must give any other recipients of the Work or Derivative Works a copy of this License; and + You must cause any modified files to carry prominent notices stating that You changed the files; and + You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and + If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. + +You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. + +5. Submission of Contributions. + +Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. + +6. Trademarks. + +This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. + +Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. + +In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. + +While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work + + To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.md b/README.md index d8fd2b0..69372bf 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,35 @@ -![pre-processing](https://i.postimg.cc/Z5YJnS29/python-pre-processing.png) -![data analysis](https://i.postimg.cc/dQdsSnG0/python-data-analysis.png) -![explaratory data analysis](https://i.postimg.cc/CLghyD4s/python-explaratory-data-analysis.png) +# SPHINX Walkthrough + +This is a walkthrough of the SPHINX workflow. It is intended to be a quick reference guide. The python work used in this repository is based on a different repository and the credits for the code go to the original authors. The original repository can be found [here](https://github.com/cherkavi/python-utilities) + +## Setup + +The workflow is divided into 3 steps: + +1. Generate Markdowns for the python directory + +```bash + +# Preprocessing: Generate markdown files from the original scripts +# In root directory, +bash scripts/generate_markdown.sh doc/pages +``` + +2. To embed the code into markdown files, run the following command: + +```bash +npm i -g markdown-autodocs +markdown-autodocs -c code-block -o doc/pages/* +``` + +The package is also available as github action. The action can be found [here](https://github.com/marketplace/actions/markdown-autodocs). + +3. To setup sphinx, run the following commands: + +```bash +# In Ubuntu 20.04 +sudo apt-get install texlive texlive-latex-extra pandoc +python3 -m pip install -r requirements.txt +cd doc +make html +``` diff --git a/console/envvar.py b/console/envvar.py deleted file mode 100755 index 9ebbf58..0000000 --- a/console/envvar.py +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env python - -# print environment variables - -import os -import sys - -for key, value in os.environ.items(): - s = '%s=%s' % (key, value) - print(s) diff --git a/doc/DOC.md b/doc/DOC.md deleted file mode 100644 index 55589cd..0000000 --- a/doc/DOC.md +++ /dev/null @@ -1,9 +0,0 @@ -reference to another object -@see -https://www.sphinx-doc.org/en/master/#cross-referencing-python-objects -```python - - :param image_size_id: one of the parameter - from :func:`list of sizes ` - -``` diff --git a/doc/Makefile b/doc/Makefile new file mode 100644 index 0000000..d4bb2cb --- /dev/null +++ b/doc/Makefile @@ -0,0 +1,20 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line, and also +# from the environment for the first two. +SPHINXOPTS ?= +SPHINXBUILD ?= sphinx-build +SOURCEDIR = . +BUILDDIR = _build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/doc/conf.py b/doc/conf.py new file mode 100644 index 0000000..0cbc6f6 --- /dev/null +++ b/doc/conf.py @@ -0,0 +1,76 @@ +# Configuration file for the Sphinx documentation builder. +# +# For the full list of built-in configuration values, see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html + +# -- Project information ----------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information +import os +import sys + +# -- General Paths ----------------------------------------------------------- + +sys.path.insert(0, os.path.abspath("../notebooks")) +sys.path.insert(0, os.path.abspath("..")) + +# -- General configuration --------------------------------------------------- +project = 'Python Utilities' +copyright = '2022, Franklin Selva' +author = 'Franklin Selva' + +# -- General configuration --------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration + +extensions = [ + "myst_parser", + "sphinx_rtd_theme", + "nbsphinx", + "nbsphinx_link", + "sphinx.ext.autodoc", + "sphinx.ext.napoleon", + "sphinx.ext.viewcode", + "sphinx.ext.intersphinx", + "sphinx.ext.autosummary", + "sphinx.ext.doctest", +] + +source_suffix = { + ".rst": "restructuredtext", + ".md": "markdown", +} + +templates_path = ['_templates'] +exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] + + + +# -- Options for HTML output ------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output + +html_theme = 'sphinx_rtd_theme' +html_theme_path = ["_themes", ] +html_static_path = ['_static'] + +html_theme_options = { + 'logo_only': False, + 'display_version': True, + 'prev_next_buttons_location': 'bottom', + 'style_external_links': False, + 'vcs_pageview_mode': '', + 'style_nav_header_background': '#2980B9', + # 'github_url': '', + # Toc options + 'collapse_navigation': False, + 'sticky_navigation': True, + 'navigation_depth': 4, + 'includehidden': True, + 'titles_only': False +} + +# -- Options for MystParser -------------------------------------------------- + +# REFERENCE: https://myst-parser.readthedocs.io/en/latest/syntax/optional.html?highlight=anchor#auto-generated-header-anchors +myst_heading_anchors = 3 +myst_enable_extensions = [ + "linkify", +] \ No newline at end of file diff --git a/doc/index.rst b/doc/index.rst new file mode 100644 index 0000000..8a4f30a --- /dev/null +++ b/doc/index.rst @@ -0,0 +1,34 @@ +.. Python Utilities documentation master file, created by + sphinx-quickstart on Mon Nov 7 15:23:55 2022. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Welcome to Python Utilities's documentation! +============================================ + +.. https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html + +.. include:: introduction.rst + +Table of Contents +------------------ + +* :ref:`python` +* :ref:`jupyter` +* :ref:`markdown` +* :ref:`license` + + +.. https://www.sphinx-doc.org/en/master/usage/restructuredtext/roles.html + +.. toctree:: + :maxdepth: 2 + :glob: + :titlesonly: + :caption: Contents + :hidden: + + python + jupyter + markdown + license diff --git a/doc/introduction.rst b/doc/introduction.rst new file mode 100644 index 0000000..b582029 --- /dev/null +++ b/doc/introduction.rst @@ -0,0 +1,5 @@ +Introduction +------------ + +.. include:: ../README.md + :parser: myst_parser.sphinx_ diff --git a/doc/jupyter.rst b/doc/jupyter.rst new file mode 100644 index 0000000..065cbac --- /dev/null +++ b/doc/jupyter.rst @@ -0,0 +1,14 @@ +.. _jupyter: + +Jupyter Notebook +---------------- + +.. toctree:: + :maxdepth: 1 + :numbered: + :glob: + :titlesonly: + :caption: Contents: + + notebooks/jupyter_cheatsheet.ipynb + notebooks/jupyter_introduction.ipynb \ No newline at end of file diff --git a/doc/license.rst b/doc/license.rst new file mode 100644 index 0000000..c0d9c55 --- /dev/null +++ b/doc/license.rst @@ -0,0 +1,6 @@ +.. _license: + +LICENSE +======= + +.. include:: ../LICENSE \ No newline at end of file diff --git a/doc/make.bat b/doc/make.bat new file mode 100644 index 0000000..32bb245 --- /dev/null +++ b/doc/make.bat @@ -0,0 +1,35 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=. +set BUILDDIR=_build + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.https://www.sphinx-doc.org/ + exit /b 1 +) + +if "%1" == "" goto help + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% + +:end +popd diff --git a/doc/markdown.rst b/doc/markdown.rst new file mode 100644 index 0000000..abd10be --- /dev/null +++ b/doc/markdown.rst @@ -0,0 +1,12 @@ +.. _markdown: + +Markdown Files +============== + +.. toctree:: + :maxdepth: 1 + :glob: + :numbered: + + markdown/index + markdown/* \ No newline at end of file diff --git a/doc/markdown/index.md b/doc/markdown/index.md new file mode 100644 index 0000000..df7cb3d --- /dev/null +++ b/doc/markdown/index.md @@ -0,0 +1,16 @@ +# Contents + +## Table of Contents + +- [Table of Contents](#table-of-contents) +- [This is a sub-heading](#this-is-a-sub-heading) +- [This is a sub-sub-heading](#this-is-a-sub-sub-heading) +- [Markdown Cheatsheet](utilities.md#markdown-cheatsheet) + +## This is a sub-heading + +This is a sub-heading with a [link](https://www.google.com "Google"). + +### This is a sub-sub-heading + +This is a sub-sub-heading with a [link](https://www.google.com "Google"). diff --git a/doc/markdown/utilities.md b/doc/markdown/utilities.md new file mode 100644 index 0000000..9296cf5 --- /dev/null +++ b/doc/markdown/utilities.md @@ -0,0 +1,249 @@ +# Markdown Cheatsheet + +--- + + + +## Heading 1 + + Markup : # Heading 1 # + + -OR- + + Markup : ============= (below H1 text) + +## Heading 2 + + Markup : ## Heading 2 ## + + -OR- + + Markup: --------------- (below H2 text) + +### Heading 3 + + Markup : ### Heading 3 ### + +#### Heading 4 + + Markup : #### Heading 4 #### + +Common text + + Markup : Common text + +_Emphasized text_ + + Markup : _Emphasized text_ or *Emphasized text* + +~~Strikethrough text~~ + + Markup : ~~Strikethrough text~~ + +**Strong text** + + Markup : __Strong text__ or **Strong text** + +**_Strong emphasized text_** + + Markup : ___Strong emphasized text___ or ***Strong emphasized text*** + +[Named Link](http://www.google.fr/ "Named link title") and http://www.google.fr/ or + + Markup : [Named Link](http://www.google.fr/ "Named link title") and http://www.google.fr/ or + +[heading-1](#heading-1 "Goto heading-1") + + Markup: [heading-1](#heading-1 "Goto heading-1") + +Table, like this one : + +| First Header | Second Header | +| ------------ | ------------- | +| Content Cell | Content Cell | +| Content Cell | Content Cell | + +``` +First Header | Second Header +------------- | ------------- +Content Cell | Content Cell +Content Cell | Content Cell +``` + +Adding a pipe `|` in a cell : + +| First Header | Second Header | +| ------------ | ------------- | +| Content Cell | Content Cell | +| Content Cell | \| | + +``` +First Header | Second Header +------------- | ------------- +Content Cell | Content Cell +Content Cell | \| +``` + +Left, right and center aligned table + +| Left aligned Header | Right aligned Header | Center aligned Header | +| :------------------ | -------------------: | :-------------------: | +| Content Cell | Content Cell | Content Cell | +| Content Cell | Content Cell | Content Cell | + +``` +Left aligned Header | Right aligned Header | Center aligned Header +| :--- | ---: | :---: +Content Cell | Content Cell | Content Cell +Content Cell | Content Cell | Content Cell +``` + +`code()` + + Markup : `code()` + +```javascript +var specificLanguage_code = { + data: { + lookedUpPlatform: 1, + query: "Kasabian+Test+Transmission", + lookedUpItem: { + name: "Test Transmission", + artist: "Kasabian", + album: "Kasabian", + picture: null, + link: "http://open.spotify.com/track/5jhJur5n4fasblLSCOcrTp", + }, + }, +}; +``` + + Markup : ```javascript + ``` + +- Bullet list + - Nested bullet + - Sub-nested bullet etc +- Bullet list item 2 + +``` + Markup : * Bullet list + * Nested bullet + * Sub-nested bullet etc + * Bullet list item 2 + +-OR- + + Markup : - Bullet list + - Nested bullet + - Sub-nested bullet etc + - Bullet list item 2 +``` + +1. A numbered list + 1. A nested numbered list + 2. Which is numbered +2. Which is numbered + +``` + Markup : 1. A numbered list + 1. A nested numbered list + 2. Which is numbered + 2. Which is numbered +``` + +- [ ] An uncompleted task +- [x] A completed task + +``` + Markup : - [ ] An uncompleted task + - [x] A completed task +``` + +- [ ] An uncompleted task + - [ ] A subtask + +``` + Markup : - [ ] An uncompleted task + - [ ] A subtask +``` + +> Blockquote +> +> > Nested blockquote + + Markup : > Blockquote + >> Nested Blockquote + +_Horizontal line :_ + +--- + + Markup : - - - - + +_Image with alt :_ + +![picture alt](http://via.placeholder.com/200x150 "Title is optional") + + Markup : ![picture alt](http://via.placeholder.com/200x150 "Title is optional") + +Foldable text: + +
+ Title 1 +

Content 1 Content 1 Content 1 Content 1 Content 1

+
+
+ Title 2 +

Content 2 Content 2 Content 2 Content 2 Content 2

+
+ + Markup :
+ Title 1 +

Content 1 Content 1 Content 1 Content 1 Content 1

+
+ +```html +

HTML

+

Some HTML code here

+``` + +Link to a specific part of the page: + +[Go To TOP](#TOP) + + Markup : [text goes here](#section_name) + section_title + +Hotkey: + +⌘F + +⇧⌘F + + Markup : ⌘F + +Hotkey list: + +| Key | Symbol | +| --------- | ------ | +| Option | ⌥ | +| Control | ⌃ | +| Command | ⌘ | +| Shift | ⇧ | +| Caps Lock | ⇪ | +| Tab | ⇥ | +| Esc | ⎋ | +| Power | ⌽ | +| Return | ↩ | +| Delete | ⌫ | +| Up | ↑ | +| Down | ↓ | +| Left | ← | +| Right | → | + +Emoji: + +:exclamation: Use emoji icons to enhance text. :+1: Look up emoji codes at [emoji-cheat-sheet.com](http://emoji-cheat-sheet.com/) + + Markup : Code appears between colons :EMOJICODE: diff --git a/doc/notebooks/jupyter_cheatsheet.ipynb b/doc/notebooks/jupyter_cheatsheet.ipynb new file mode 100644 index 0000000..897f72f --- /dev/null +++ b/doc/notebooks/jupyter_cheatsheet.ipynb @@ -0,0 +1,4037 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Jupyter Notebook Cheat Sheet" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Shortcuts\n", + "`ESC` Toggle between cell editing (green line) and cell functions (blue line)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "`a` add a cell Above" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "`b` add a cell Below" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "`x` Cut a cell (delete)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "`v` Paste a cell" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Help and Documentation" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### **TAB**\n", + "\n", + "Use TAB to list possible options" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "df = pd.DataFrame({\"a\": [1,2,3], \"b\": [4,5,6]})" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.melt" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "TAB with imports" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "from matplotlib import pyplot " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Wildcard matching" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "str.find\n", + "str.isidentifier\n", + "str.rfind\n", + "str.zfill" + ] + } + ], + "source": [ + "str.*fi*?\n", + "# gives the list of matching methods" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### **?** or **help(command)**\n", + "\n", + "Use `?` after a command name to get the help" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Help on built-in function len in module builtins:\n", + "\n", + "len(obj, /)\n", + " Return the number of items in a container.\n", + "\n" + ] + } + ], + "source": [ + "help(len)\n", + "# inline help" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[0;31mSignature:\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mobj\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\u001b[0m\n", + "\u001b[0;31mDocstring:\u001b[0m Return the number of items in a container.\n", + "\u001b[0;31mType:\u001b[0m builtin_function_or_method\n" + ] + } + ], + "source": [ + "len?\n", + "# in separate window" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[0;31mType:\u001b[0m DataFrame\n", + "\u001b[0;31mString form:\u001b[0m\n", + " a b\n", + "0 1 4\n", + "1 2 5\n", + "2 3 6\n", + "\u001b[0;31mLength:\u001b[0m 3\n", + "\u001b[0;31mFile:\u001b[0m /usr/lib/python3/dist-packages/pandas/core/frame.py\n", + "\u001b[0;31mDocstring:\u001b[0m \n", + "Two-dimensional size-mutable, potentially heterogeneous tabular data\n", + "structure with labeled axes (rows and columns). Arithmetic operations\n", + "align on both row and column labels. Can be thought of as a dict-like\n", + "container for Series objects. The primary pandas data structure.\n", + "\n", + "Parameters\n", + "----------\n", + "data : ndarray (structured or homogeneous), Iterable, dict, or DataFrame\n", + " Dict can contain Series, arrays, constants, or list-like objects\n", + "\n", + " .. versionchanged :: 0.23.0\n", + " If data is a dict, column order follows insertion-order for\n", + " Python 3.6 and later.\n", + "\n", + " .. versionchanged :: 0.25.0\n", + " If data is a list of dicts, column order follows insertion-order\n", + " for Python 3.6 and later.\n", + "\n", + "index : Index or array-like\n", + " Index to use for resulting frame. Will default to RangeIndex if\n", + " no indexing information part of input data and no index provided\n", + "columns : Index or array-like\n", + " Column labels to use for resulting frame. Will default to\n", + " RangeIndex (0, 1, 2, ..., n) if no column labels are provided\n", + "dtype : dtype, default None\n", + " Data type to force. Only a single dtype is allowed. If None, infer\n", + "copy : boolean, default False\n", + " Copy data from inputs. Only affects DataFrame / 2d ndarray input\n", + "\n", + "See Also\n", + "--------\n", + "DataFrame.from_records : Constructor from tuples, also record arrays.\n", + "DataFrame.from_dict : From dicts of Series, arrays, or dicts.\n", + "DataFrame.from_items : From sequence of (key, value) pairs\n", + " read_csv, pandas.read_table, pandas.read_clipboard.\n", + "\n", + "Examples\n", + "--------\n", + "Constructing DataFrame from a dictionary.\n", + "\n", + ">>> d = {'col1': [1, 2], 'col2': [3, 4]}\n", + ">>> df = pd.DataFrame(data=d)\n", + ">>> df\n", + " col1 col2\n", + "0 1 3\n", + "1 2 4\n", + "\n", + "Notice that the inferred dtype is int64.\n", + "\n", + ">>> df.dtypes\n", + "col1 int64\n", + "col2 int64\n", + "dtype: object\n", + "\n", + "To enforce a single dtype:\n", + "\n", + ">>> df = pd.DataFrame(data=d, dtype=np.int8)\n", + ">>> df.dtypes\n", + "col1 int8\n", + "col2 int8\n", + "dtype: object\n", + "\n", + "Constructing DataFrame from numpy ndarray:\n", + "\n", + ">>> df2 = pd.DataFrame(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]),\n", + "... columns=['a', 'b', 'c'])\n", + ">>> df2\n", + " a b c\n", + "0 1 2 3\n", + "1 4 5 6\n", + "2 7 8 9\n" + ] + } + ], + "source": [ + "df?" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Source code **??**\n", + "\n", + "Access source code with `??`" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[0;31mSignature:\u001b[0m \u001b[0mdf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmean\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0maxis\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mskipna\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlevel\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnumeric_only\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\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", + "Return the mean of the values for the requested axis.\n", + "\n", + "Parameters\n", + "----------\n", + "axis : {index (0), columns (1)}\n", + " Axis for the function to be applied on.\n", + "skipna : bool, default True\n", + " Exclude NA/null values when computing the result.\n", + "level : int or level name, default None\n", + " If the axis is a MultiIndex (hierarchical), count along a\n", + " particular level, collapsing into a Series.\n", + "numeric_only : bool, default None\n", + " Include only float, int, boolean columns. If None, will attempt to use\n", + " everything, then use only numeric data. Not implemented for Series.\n", + "**kwargs\n", + " Additional keyword arguments to be passed to the function.\n", + "\n", + "Returns\n", + "-------\n", + "Series or DataFrame (if level specified)\n", + "\u001b[0;31mSource:\u001b[0m \n", + " \u001b[0;34m@\u001b[0m\u001b[0mSubstitution\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\u001b[0m\n", + "\u001b[0;34m\u001b[0m \u001b[0mdesc\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdesc\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n", + "\u001b[0;34m\u001b[0m \u001b[0mname1\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mname1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n", + "\u001b[0;34m\u001b[0m \u001b[0mname2\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mname2\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n", + "\u001b[0;34m\u001b[0m \u001b[0maxis_descr\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0maxis_descr\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n", + "\u001b[0;34m\u001b[0m \u001b[0mmin_count\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[0msee_also\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0msee_also\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\n", + "\u001b[0;34m\u001b[0m \u001b[0mexamples\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mexamples\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\n", + "\u001b[0;34m\u001b[0m \u001b[0;34m@\u001b[0m\u001b[0mAppender\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0m_num_doc\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n", + "\u001b[0;34m\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mstat_func\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[0maxis\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mskipna\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlevel\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnumeric_only\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\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[0;32mif\u001b[0m \u001b[0mname\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m\"median\"\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n", + "\u001b[0;34m\u001b[0m \u001b[0mnv\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalidate_median\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtuple\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mkwargs\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[0mnv\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalidate_stat_func\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtuple\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mkwargs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfname\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\n", + "\u001b[0;34m\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mskipna\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[0mskipna\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m\u001b[0m\n", + "\u001b[0;34m\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0maxis\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[0maxis\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_stat_axis_number\u001b[0m\u001b[0;34m\u001b[0m\n", + "\u001b[0;34m\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mlevel\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;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_agg_by_level\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0maxis\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlevel\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mlevel\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mskipna\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mskipna\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_reduce\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\u001b[0m\n", + "\u001b[0;34m\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0maxis\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mskipna\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mskipna\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnumeric_only\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mnumeric_only\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;31mFile:\u001b[0m /usr/lib/python3/dist-packages/pandas/core/generic.py\n", + "\u001b[0;31mType:\u001b[0m method\n" + ] + } + ], + "source": [ + "df.mean??" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Shell Commands\n", + "\n", + "Just like using your shell" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "jupyter_cheetsheet.ipynb\n" + ] + } + ], + "source": [ + "ls" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[Errno 2] No such file or directory: './../jupyter/'\n", + "/home/shasthamsa/work/sphinx-walkthrough/notebooks\n" + ] + } + ], + "source": [ + "cd ./../jupyter/" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [], + "source": [ + "mkdir -p blah" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[0m\u001b[01;34mblah\u001b[0m/ jupyter_cheetsheet.ipynb\n" + ] + } + ], + "source": [ + "ls" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Passing shell commands to python" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'/home/shasthamsa/work/sphinx-walkthrough/notebooks'" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pwd" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [], + "source": [ + "current_dir = !pwd" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['/home/shasthamsa/work/sphinx-walkthrough/notebooks']" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "current_dir" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Magic functions\n", + "Magic functions are 'extra' functions available in Jupyter notebook, that are not 'python' code but tell Jupyter to process the command in a specific way\n", + "\n", + "Magic functions start with `%`" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\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: \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", + " https://peps.python.org/pep-0215/. 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: \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", + " 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]: \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 - set bookmark to current dir\n", + " %bookmark - set bookmark to \n", + " %bookmark -l - list all bookmarks\n", + " %bookmark -d - remove bookmark\n", + " %bookmark -r - remove all bookmarks\n", + " \n", + " You can later on access a bookmarked folder with::\n", + " \n", + " %cd -b \n", + " \n", + " or simply '%cd ' if there is no directory called 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 :magic:`%dhist` shows this history nicely formatted. You can\n", + " also do ``cd -`` to see directory history conveniently.\n", + " Usage:\n", + " \n", + " - ``cd 'dir'``: changes to directory 'dir'.\n", + " - ``cd -``: changes to the last visited directory.\n", + " - ``cd -``: changes to the n-th directory in the directory history.\n", + " - ``cd --foo``: change to directory that matches 'foo' in history\n", + " - ``cd -b ``: jump to a bookmark set by %bookmark\n", + " - Hitting a tab key after ``cd -b`` allows you to tab-complete\n", + " bookmark names.\n", + " \n", + " .. note::\n", + " ``cd `` is enough if there is no directory\n", + " ````, but a bookmark with the name exists.\n", + " \n", + " Options:\n", + " \n", + " -q Be quiet. Do not print the working directory after the\n", + " cd command is executed. By default IPython's cd\n", + " command does print this directory, since the default\n", + " prompts do not display path information.\n", + " \n", + " .. note::\n", + " Note that ``!cd`` doesn't work for this purpose because the shell\n", + " where ``!command`` runs is immediately discarded after executing\n", + " '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", + " AliasManager\n", + " DisplayFormatter\n", + " HistoryManager\n", + " IPCompleter\n", + " LoggingMagics\n", + " MagicsManager\n", + " OSMagics\n", + " PrefilterManager\n", + " ScriptMagics\n", + " TerminalInteractiveShell\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(Completer) options\n", + " ----------------------------\n", + " IPCompleter.backslash_combining_completions=\n", + " Enable unicode completions, e.g. \\alpha . Includes completion of latex\n", + " commands, unicode names, and expanding unicode characters back to latex\n", + " commands.\n", + " Current: True\n", + " IPCompleter.debug=\n", + " Enable debug for the Completer. Mostly print extra information for\n", + " experimental jedi integration.\n", + " Current: False\n", + " IPCompleter.greedy=\n", + " Activate greedy completion\n", + " PENDING DEPRECATION. this is now mostly taken care of with Jedi.\n", + " This will enable completion on elements of lists, results of function calls, etc.,\n", + " but can be unsafe because the code is actually evaluated on TAB.\n", + " Current: False\n", + " IPCompleter.jedi_compute_type_timeout=\n", + " Experimental: restrict time (in milliseconds) during which Jedi can compute types.\n", + " Set to 0 to stop computing types. Non-zero value lower than 100ms may hurt\n", + " performance by preventing jedi to build its cache.\n", + " Current: 400\n", + " IPCompleter.limit_to__all__=\n", + " DEPRECATED as of version 5.0.\n", + " Instruct the completer to use __all__ for the completion\n", + " Specifically, when completing on ``object.``.\n", + " When True: only those names in obj.__all__ will be included.\n", + " When False [default]: the __all__ attribute is ignored\n", + " Current: False\n", + " IPCompleter.merge_completions=\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", + " Current: True\n", + " IPCompleter.omit__names=\n", + " Instruct the completer to omit private method names\n", + " Specifically, when completing on ``object.``.\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", + " Choices: any of [0, 1, 2]\n", + " Current: 2\n", + " IPCompleter.profile_completions=\n", + " If True, emit profiling data for completion subsystem using cProfile.\n", + " Current: False\n", + " IPCompleter.profiler_output_dir=\n", + " Template for path at which to output profile data for completions.\n", + " Current: '.completion_profiles'\n", + " IPCompleter.use_jedi=\n", + " Experimental: Use Jedi to generate autocompletions. Default to True if jedi\n", + " is installed.\n", + " Current: True\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 --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 , -b \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", + " to go to directory number .\n", + " \n", + " Note that most of time, you should view directory history by entering\n", + " cd -.\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 \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 gtk4 # enable Gtk4 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 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", + " If no arguments are given, loads the history of this session up to this\n", + " point.\n", + " \n", + " Options:\n", + " \n", + " -r : 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 : 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\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', 'gtk4', '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", + " 'gtk4', 'inline', 'ipympl', 'nbagg', 'notebook', 'osx', 'pdf',\n", + " 'ps', 'qt', 'qt4', 'qt5', 'qt6', 'svg', 'tk', 'widget', 'wx').\n", + " If given, the corresponding matplotlib backend is used,\n", + " otherwise it will be matplotlib's default (which you can set in\n", + " your matplotlib 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", + " 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.com, returning the URL.\n", + " \n", + " Usage:\n", + " %pastebin [-d \"Custom description\"][-e 24] 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", + " If no arguments are given, uploads the history of this session up to\n", + " this point.\n", + " \n", + " Options:\n", + " \n", + " -d: Pass a custom description. The default will say\n", + " \"Pasted from IPython\".\n", + " -e: Pass number of days for the link to be expired.\n", + " The default will be 7 days.\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 \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 \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 \n", + " save profile results as shown on screen to a text\n", + " file. The profile is still shown on screen.\n", + " \n", + " -D \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", + " If no parameter is given, prints out history of current session up to\n", + " this point. ::\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', 'gtk4', 'inline', 'ipympl', 'nbagg', 'notebook',\n", + " 'osx', 'pdf', 'ps', 'qt', 'qt4', 'qt5', 'qt6', 'svg', 'tk',\n", + " 'widget', 'wx'). If given, the corresponding matplotlib\n", + " backend is used, otherwise it will be matplotlib's default\n", + " (which you 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 : 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\n", + " force reset without asking for confirmation.\n", + " -s\n", + " '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", + " --aggressive\n", + " Try to aggressively remove modules from sys.modules ; this\n", + " may allow you to reimport Python modules that have been updated and\n", + " pick up changes, but can have unattended consequences.\n", + " \n", + " in\n", + " reset input history\n", + " out\n", + " reset output history\n", + " dhist\n", + " reset directory history\n", + " array\n", + " 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", + " 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] | -d [-b] | -p [profile options] )]\n", + " ( -m mod | filename ) [args]\n", + " \n", + " The filename argument should be either a pure Python script (with\n", + " extension ``.py``), or a file with custom IPython syntax (such as\n", + " magics). If the latter, the file can be either a script with ``.ipy``\n", + " extension, or a Jupyter notebook with ``.ipynb`` extension. When running\n", + " a Jupyter notebook, the output from print statements and other\n", + " displayed objects will appear in the terminal (even matplotlib figures\n", + " will open, if a terminal-compliant backend is being used). Note that,\n", + " at the system command line, the ``jupyter run`` command offers similar\n", + " functionality for executing notebooks (albeit currently with some\n", + " differences in supported options).\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`` option can be given, where \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 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 [history]\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", + " The history argument uses the same syntax as %history for input ranges,\n", + " then saves the lines to the filename you specify.\n", + " \n", + " If no ranges are specified, saves history of the current session up to\n", + " this point.\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", + " Stored 'l' (list)\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 bar`` - Store the *current* value of the variables spam\n", + " and bar 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, aliases and directory history\n", + " from store (overwrite current vals)\n", + " * ``%store -r spam bar`` - Refresh specified variables and aliases 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::\n", + " The time needed by Python to compile the given expression will be\n", + " reported if it is more than 0.1s.\n", + " \n", + " In the example below, the actual exponentiation is done by Python\n", + " at compilation time, so while the expression can take a noticeable\n", + " amount of time to compute, that time is purely due to the\n", + " 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 -r [-t|-c] -q -p

-o] statement\n", + " or in cell mode:\n", + " %%timeit [-n -r [-t|-c] -q -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: execute the given statement times in a loop. If is not\n", + " provided, is determined so as to get sufficient accuracy.\n", + " \n", + " -r: number of repeats , each consisting of 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

: use a precision of

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", + " 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]: \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", + " 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", + " 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", + " When in verbose mode the value --show (and --hide)\n", + " will respectively show (or hide) frames with ``__tracebackhide__ =\n", + " True`` value set.\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 , -b \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