Skip to content

Commit

Permalink
updated Jupyter intro
Browse files Browse the repository at this point in the history
  • Loading branch information
diazdc committed Oct 25, 2019
1 parent 24f3334 commit 5bd6fd8
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 132 deletions.
97 changes: 31 additions & 66 deletions workshops/.ipynb_checkpoints/Jupyter_Lab_intro-checkpoint.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"\n",
"# Interactive Coding With [Jupyter Lab](https://jupyterlab.readthedocs.io/en/stable/)\n",
"\n",
"From the docs:\n",
"\n",
">JupyterLab enables you to work with documents and activities such as Jupyter notebooks, text editors, terminals, and custom components in a flexible, integrated, and extensible manner. You can arrange multiple documents and activities side by side in the work area using tabs and splitters."
]
},
Expand Down Expand Up @@ -71,12 +73,8 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"deletable": true,
"editable": true,
"jupyter": {
"outputs_hidden": true
}
"editable": true
},
"outputs": [],
"source": [
Expand All @@ -93,12 +91,8 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"deletable": true,
"editable": true,
"jupyter": {
"outputs_hidden": true
}
"editable": true
},
"outputs": [],
"source": [
Expand Down Expand Up @@ -130,12 +124,8 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"deletable": true,
"editable": true,
"jupyter": {
"outputs_hidden": true
}
"editable": true
},
"outputs": [],
"source": [
Expand Down Expand Up @@ -176,7 +166,7 @@
"\n",
"Interactive programming directly from the a python script is very similar to debugging, because you can evaluate each line of your script in a step-wise fashion. This is quite similar to notebook cell, but instead you highlight the amount of text you want to send to the interpreter.\n",
"\n",
"Here we're going to open a regular python script which contains a few examples from previous problem sets. You can right click on the editor for any notebook or python script and select \"New Console\" to bring up the IPython interpreter for the file you are currently editing. **Shift+enter** is the default shortcut for sending your highlighted text to the interpreter.\n",
"Here we're going to open a regular python script from the Jupyter Lab sidebar which contains a few examples from previous problem sets. You can right click on the editor for any notebook or python script and select \"New Console\" to bring up the IPython interpreter for the file you are currently editing. **Shift+enter** is the default shortcut for sending your highlighted text to the interpreter.\n",
"\n",
"**Note:** Sending text from a Python script to the interpreter requires that you highlight code with the **correct** indentation (e.g. four spaces). "
]
Expand All @@ -203,32 +193,22 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"deletable": true,
"editable": true,
"jupyter": {
"outputs_hidden": true
}
"editable": true
},
"outputs": [],
"source": [
"!ls\n",
"\n",
"!pwd\n",
"\n",
"!echo \"printing from the shell\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"deletable": true,
"editable": true,
"jupyter": {
"outputs_hidden": true
}
"editable": true
},
"outputs": [],
"source": [
Expand All @@ -248,17 +228,12 @@
"editable": true
},
"source": [
"### IPython \"magic\" commands\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"source": [
">IPython has a set of predefined ‘magic functions’ that you can call with a command line style syntax. There are two kinds of magics, line-oriented and cell-oriented. Line magics are prefixed with the **%** character and work much like OS command-line calls: they get as an argument the rest of the line, where arguments are passed without parentheses or quotes. Cell magics are prefixed with a double **%%**, and they are functions that get as an argument not only the rest of the line, but also the lines below it in a separate argument.\n",
"### IPython \"magic\" commands\n",
"\n",
"From [the IPython manual](https://ipython.readthedocs.io/en/stable/interactive/magics.html):\n",
"\n",
"\n",
">IPython has a set of predefined ‘magic functions’ that you can call with a command line style syntax. There are two kinds of magics, line-oriented and cell-oriented. Line magics are prefixed with the `%` character and work much like OS command-line calls: they get as an argument the rest of the line, where arguments are passed without parentheses or quotes. Cell magics are prefixed with a double `%%`, and they are functions that get as an argument not only the rest of the line, but also the lines below it in a separate argument.\n",
"\n",
"Let's take a look a few of the most useful IPython magic commands. You can find a complete summary of them in [this section](https://ipython.readthedocs.io/en/stable/interactive/magics.html) of IPython manual.\n",
"\n",
Expand Down Expand Up @@ -302,9 +277,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"#### %system\n",
"#### %%writefile\n",
"\n",
"Shell execute - run shell command and capture output (!! is short-hand)"
"Write the contents of a cell to a file."
]
},
{
Expand All @@ -316,28 +291,17 @@
},
"outputs": [],
"source": [
"%system"
"%%writefile message.txt\n",
"\"don't forget to commit your changes!\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### %time\n",
"#### %time \n",
"\n",
"Time execution of a Python statement or expression."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": true,
"editable": true
},
"outputs": [],
"source": [
"%time"
"Time execution of a Python statement or expression. When used with a single `%` the time for a command on a single line is returned. When used with `%%` the run time for the whole cell is returned."
]
},
{
Expand All @@ -349,19 +313,20 @@
},
"outputs": [],
"source": [
"%load Jupyter_Lab_ps1.py"
"%%time\n",
"\n",
"import time\n",
"time.sleep(2)\n",
"print(\"wake up\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"deletable": true,
"editable": true
},
"outputs": [],
"cell_type": "markdown",
"metadata": {},
"source": [
"%pdb on"
"#### %load\n",
"\n",
"Load a python script into a cell."
]
},
{
Expand All @@ -373,7 +338,7 @@
},
"outputs": [],
"source": [
"%run Jupyter_Lab_ps1.py Daniel"
"%load Jupyter_Lab_ps1.py"
]
},
{
Expand Down
Loading

0 comments on commit 5bd6fd8

Please sign in to comment.