##// END OF EJS Templates
Pulling in content and rewriting from ipython-in-depth.
Pulling in content and rewriting from ipython-in-depth.

File last commit:

r17495:da98aae1
r17496:b0d6ca14
Show More
Working With Code Cells.ipynb
170 lines | 4.2 KiB | text/plain | TextLexer
/ examples / Notebook / Working With Code Cells.ipynb
Fernando Perez
Update and rename basic quantum computing with sympy example notebook.
r5779 {
"metadata": {
Brian E. Granger
Updating nb tutorials
r16108 "name": "",
Brian E. Granger
Adding moved content.
r17495 "signature": "sha256:1cf51b66a39fb370f2fb3d08af95cfc79b8884f310509181b3b0586400e20b81"
Fernando Perez
Update and rename basic quantum computing with sympy example notebook.
r5779 },
Brian Granger
Updating example notebooks to v3 format.
r6035 "nbformat": 3,
MinRK
rebuild example notebooks...
r7739 "nbformat_minor": 0,
Fernando Perez
Update and rename basic quantum computing with sympy example notebook.
r5779 "worksheets": [
{
"cells": [
{
Brian Granger
First go and reorganizing the examples.
r9191 "cell_type": "heading",
"level": 1,
"metadata": {},
"source": [
"Running Code in the IPython Notebook"
]
},
{
Fernando Perez
Update and rename basic quantum computing with sympy example notebook.
r5779 "cell_type": "markdown",
MinRK
rebuild example notebooks...
r7739 "metadata": {},
Fernando Perez
Update and rename basic quantum computing with sympy example notebook.
r5779 "source": [
Brian E. Granger
Adding moved content.
r17495 "First and foremost, the IPython Notebook is an interactive environment for writing and running code. IPython is capable of running code in a wide range of languages. However, in IPython 2.0, the default kernel runs Python code."
Brian Granger
First go and reorganizing the examples.
r9191 ]
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Code cells allow you to enter and run Python code"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
Brian E. Granger
Adding moved content.
r17495 "Run a code cell using `Shift-Enter` or pressing the <button><i class=\"icon-play fa fa-play\"></i></button> button in the toolbar above:"
Fernando Perez
Update and rename basic quantum computing with sympy example notebook.
r5779 ]
},
{
"cell_type": "code",
Brian Granger
First go and reorganizing the examples.
r9191 "collapsed": false,
Fernando Perez
Update and rename basic quantum computing with sympy example notebook.
r5779 "input": [
Brian Granger
First go and reorganizing the examples.
r9191 "a = 10"
Fernando Perez
Update and rename basic quantum computing with sympy example notebook.
r5779 ],
"language": "python",
MinRK
rebuild example notebooks...
r7739 "metadata": {},
Fernando Perez
Update and rename basic quantum computing with sympy example notebook.
r5779 "outputs": [],
Brian E. Granger
Updating nb tutorials
r16108 "prompt_number": 1
Fernando Perez
Update and rename basic quantum computing with sympy example notebook.
r5779 },
{
"cell_type": "code",
Brian Granger
First go and reorganizing the examples.
r9191 "collapsed": false,
Fernando Perez
Update and rename basic quantum computing with sympy example notebook.
r5779 "input": [
Thomas Kluyver
More changes to example notebooks for Python 3 compatibility
r9198 "print(a)"
Fernando Perez
Update and rename basic quantum computing with sympy example notebook.
r5779 ],
"language": "python",
MinRK
rebuild example notebooks...
r7739 "metadata": {},
Brian Granger
First go and reorganizing the examples.
r9191 "outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"10\n"
]
}
],
Brian E. Granger
Updating nb tutorials
r16108 "prompt_number": 2
Fernando Perez
Update and rename basic quantum computing with sympy example notebook.
r5779 },
{
Brian E. Granger
Adding moved content.
r17495 "cell_type": "markdown",
"metadata": {},
"source": [
"There are two other keyboard shortcuts for running code:\n",
"\n",
"* `Alt-Enter` runs the current cell and inserts a new one below.\n",
"* `Ctrl-Enter` run the current cell and enters command mode."
]
},
{
Brian Granger
First go and reorganizing the examples.
r9191 "cell_type": "heading",
"level": 2,
MinRK
rebuild example notebooks...
r7739 "metadata": {},
Fernando Perez
Update and rename basic quantum computing with sympy example notebook.
r5779 "source": [
Brian Granger
First go and reorganizing the examples.
r9191 "Managing the IPython Kernel"
Fernando Perez
Update and rename basic quantum computing with sympy example notebook.
r5779 ]
},
{
"cell_type": "markdown",
MinRK
rebuild example notebooks...
r7739 "metadata": {},
Fernando Perez
Update and rename basic quantum computing with sympy example notebook.
r5779 "source": [
Brian E. Granger
Adding moved content.
r17495 "Code is run in a separate process called the IPython Kernel. The Kernel can be interrupted or restarted. Try running the following cell and then hit the <button><i class='icon-stop fa fa-stop'></i></button> button in the toolbar above."
Fernando Perez
Update and rename basic quantum computing with sympy example notebook.
r5779 ]
},
{
"cell_type": "code",
Brian Granger
First go and reorganizing the examples.
r9191 "collapsed": false,
Fernando Perez
Update and rename basic quantum computing with sympy example notebook.
r5779 "input": [
Brian Granger
First go and reorganizing the examples.
r9191 "import time\n",
"time.sleep(10)"
Fernando Perez
Update and rename basic quantum computing with sympy example notebook.
r5779 ],
"language": "python",
MinRK
rebuild example notebooks...
r7739 "metadata": {},
Brian E. Granger
Updating nb tutorials
r16108 "outputs": []
Fernando Perez
Update and rename basic quantum computing with sympy example notebook.
r5779 },
{
"cell_type": "markdown",
MinRK
rebuild example notebooks...
r7739 "metadata": {},
Fernando Perez
Update and rename basic quantum computing with sympy example notebook.
r5779 "source": [
Brian Granger
First go and reorganizing the examples.
r9191 "If the Kernel dies you will be prompted to restart it. Here we call the low-level system libc.time routine with the wrong argument via\n",
"ctypes to segfault the Python interpreter:"
Fernando Perez
Update and rename basic quantum computing with sympy example notebook.
r5779 ]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
Brian Granger
First go and reorganizing the examples.
r9191 "import sys\n",
"from ctypes import CDLL\n",
Brian E. Granger
Adding moved content.
r17495 "# This will crash a Linux or Mac system\n",
"# equivalent calls can be made on Windows\n",
Thomas Kluyver
More changes to example notebooks for Python 3 compatibility
r9198 "dll = 'dylib' if sys.platform == 'darwin' else 'so.6'\n",
Brian Granger
First go and reorganizing the examples.
r9191 "libc = CDLL(\"libc.%s\" % dll) \n",
"libc.time(-1) # BOOM!!"
Fernando Perez
Update and rename basic quantum computing with sympy example notebook.
r5779 ],
"language": "python",
MinRK
rebuild example notebooks...
r7739 "metadata": {},
MinRK
use mpl showcase instead of pylab examples...
r15188 "outputs": []
Brian Granger
First go and reorganizing the examples.
r9191 },
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
Brian E. Granger
Adding moved content.
r17495 "Cell menu"
Fernando Perez
Update and rename basic quantum computing with sympy example notebook.
r5779 ]
},
{
"cell_type": "markdown",
MinRK
rebuild example notebooks...
r7739 "metadata": {},
Fernando Perez
Update and rename basic quantum computing with sympy example notebook.
r5779 "source": [
Brian E. Granger
Adding moved content.
r17495 "The \"Cell\" menu has a number of menu items for running code in different ways. These includes:\n",
"\n",
"* Run and Select Below\n",
"* Run and Insert Below\n",
"* Run All\n",
"* Run All Above\n",
"* Run All Below"
Fernando Perez
Update and rename basic quantum computing with sympy example notebook.
r5779 ]
},
{
Brian Granger
First go and reorganizing the examples.
r9191 "cell_type": "heading",
"level": 2,
MinRK
rebuild example notebooks...
r7739 "metadata": {},
Fernando Perez
Update and rename basic quantum computing with sympy example notebook.
r5779 "source": [
Brian E. Granger
Adding moved content.
r17495 "Restarting the kernels"
Fernando Perez
Update and rename basic quantum computing with sympy example notebook.
r5779 ]
},
{
Brian Granger
First go and reorganizing the examples.
r9191 "cell_type": "markdown",
MinRK
rebuild example notebooks...
r7739 "metadata": {},
Brian Granger
First go and reorganizing the examples.
r9191 "source": [
Brian E. Granger
Adding moved content.
r17495 "The kernel maintains the state of a notebook's computations. You can reset this state by restarting the kernel. This is done by clicking on the <button><i class='icon-repeat'></i></button> in the toolbar above."
Fernando Perez
Update and rename basic quantum computing with sympy example notebook.
r5779 ]
}
MinRK
rebuild example notebooks...
r7739 ],
"metadata": {}
Fernando Perez
Update and rename basic quantum computing with sympy example notebook.
r5779 }
]
MinRK
use mpl showcase instead of pylab examples...
r15188 }