Skip to content

Commit

Permalink
Changes for Python 3.10+ features and missing graphics
Browse files Browse the repository at this point in the history
  • Loading branch information
timsnow committed Oct 11, 2024
1 parent 3572c06 commit 9abddf9
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 41 deletions.
45 changes: 43 additions & 2 deletions 01 - The Basics/02 - Flow Control.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,47 @@
"On the next loop around the `while` keyword sees that `keep_going` is no longer `True` and so we `break` out of the loop and can move on to the next piece of code."
]
},
{
"cell_type": "markdown",
"id": "ae0250b5",
"metadata": {},
"source": [
"## `match` statements\n",
"\n",
"What if we performantly want to check a variable against multiple possible values?\n",
"\n",
"In other languages such flow control is called a `switch` statement, in Python it's called `match`."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "66c29c8c",
"metadata": {},
"outputs": [],
"source": [
"import datetime\n",
"today = datetime.date.today()\n",
"\n",
"match today.weekday():\n",
" case 0:\n",
" print(\"Today is Sunday\")\n",
" case 1:\n",
" print(\"Today is Monday\")\n",
" case 2:\n",
" print(\"Today is Tuesday\")\n",
" case 3:\n",
" print(\"Today is Wednesday\")\n",
" case 4:\n",
" print(\"Today is Thursday\")\n",
" case 5:\n",
" print(\"Today is Friday\")\n",
" case 6:\n",
" print(\"Today is Saturday\")\n",
" case _:\n",
" print(\"Today is a day I don't know\")"
]
},
{
"cell_type": "markdown",
"id": "1fb9627b",
Expand All @@ -455,7 +496,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "dev",
"language": "python",
"name": "python3"
},
Expand All @@ -469,7 +510,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
"version": "3.12.2"
}
},
"nbformat": 4,
Expand Down
16 changes: 8 additions & 8 deletions 02 - Data Handling/01 - Data Ingest.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
"metadata": {},
"outputs": [],
"source": [
"!pip install h5py\n",
"!pip install numpy\n",
"!pip install matplotlib\n",
"%pip install h5py\n",
"%pip install numpy\n",
"%pip install matplotlib\n",
"\n",
"!git clone https://github.com/timsnow/advanced_sas_training_course\n",
"%git clone https://github.com/timsnow/advanced_sas_training_course\n",
"%cd 'advanced_sas_training_course/02 - Data Handling'"
]
},
Expand All @@ -51,7 +51,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"id": "6d95abee",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -635,7 +635,7 @@
"\n",
"The beginner's cheatsheet is probably enough to be going on for now:\n",
"\n",
"![Beginner's cheatsheet](https://github.com/matplotlib/cheatsheets/raw/master/handout-beginner.png)\n",
"![Beginner's cheatsheet](https://camo.githubusercontent.com/39835016ed0289de8d01ba786509de814caba7bf193c017e245a87a1bd9d70b7/68747470733a2f2f6d6174706c6f746c69622e6f72672f63686561747368656574732f68616e646f75742d626567696e6e65722e706e67)\n",
"\n",
"\n",
"With all of this in mind - we can finally arrive at a graph like this:"
Expand Down Expand Up @@ -733,7 +733,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "dev",
"language": "python",
"name": "python3"
},
Expand All @@ -747,7 +747,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
"version": "3.12.2"
}
},
"nbformat": 4,
Expand Down
12 changes: 6 additions & 6 deletions 02 - Data Handling/02 - Function Fitting with lmfit.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
"metadata": {},
"outputs": [],
"source": [
"!pip install h5py\n",
"!pip install lmfit\n",
"!pip install numpy\n",
"!pip install matplotlib\n",
"%pip install h5py\n",
"%pip install lmfit\n",
"%pip install numpy\n",
"%pip install matplotlib\n",
"\n",
"!git clone https://github.com/timsnow/advanced_sas_training_course\n",
"%git clone https://github.com/timsnow/advanced_sas_training_course\n",
"%cd 'advanced_sas_training_course/02 - Data Handling'"
]
},
Expand Down Expand Up @@ -583,7 +583,7 @@
"metadata": {},
"outputs": [],
"source": [
"numpy.savetxt(file_path, array, delimiter='\\t', newline='\\n', header='', footer='', comments='# ')"
"np.savetxt(file_path, array, delimiter='\\t', newline='\\n', header='', footer='', comments='# ')"
]
},
{
Expand Down
10 changes: 5 additions & 5 deletions 02 - Data Handling/03 - Exercises.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
"metadata": {},
"outputs": [],
"source": [
"!pip install h5py\n",
"!pip install lmfit\n",
"!pip install numpy\n",
"!pip install matplotlib\n",
"%pip install h5py\n",
"%pip install lmfit\n",
"%pip install numpy\n",
"%pip install matplotlib\n",
"\n",
"!git clone https://github.com/timsnow/advanced_sas_training_course\n",
"%git clone https://github.com/timsnow/advanced_sas_training_course\n",
"%cd 'advanced_sas_training_course/02 - Data Handling'"
]
},
Expand Down
10 changes: 5 additions & 5 deletions 02 - Data Handling/04 - Exercises and Answers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
"metadata": {},
"outputs": [],
"source": [
"!pip install h5py\n",
"!pip install lmfit\n",
"!pip install numpy\n",
"!pip install matplotlib\n",
"%pip install h5py\n",
"%pip install lmfit\n",
"%pip install numpy\n",
"%pip install matplotlib\n",
"\n",
"!git clone https://github.com/timsnow/advanced_sas_training_course\n",
"%git clone https://github.com/timsnow/advanced_sas_training_course\n",
"%cd 'advanced_sas_training_course/02 - Data Handling'"
]
},
Expand Down
10 changes: 5 additions & 5 deletions 03 - SAS Software/01 - SasView.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
"metadata": {},
"outputs": [],
"source": [
"!pip install bumps\n",
"!pip install numpy\n",
"!pip install sasmodels\n",
"!pip install matplotlib\n",
"%pip install bumps\n",
"%pip install numpy\n",
"%pip install sasmodels\n",
"%pip install matplotlib\n",
"\n",
"!git clone https://github.com/timsnow/advanced_sas_training_course\n",
"%git clone https://github.com/timsnow/advanced_sas_training_course\n",
"%cd 'advanced_sas_training_course/03 - SAS Software'"
]
},
Expand Down
10 changes: 5 additions & 5 deletions 03 - SAS Software/02 - Exercises.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
"metadata": {},
"outputs": [],
"source": [
"!pip install bumps\n",
"!pip install numpy\n",
"!pip install sasmodels\n",
"!pip install matplotlib\n",
"%pip install bumps\n",
"%pip install numpy\n",
"%pip install sasmodels\n",
"%pip install matplotlib\n",
"\n",
"!git clone https://github.com/timsnow/advanced_sas_training_course\n",
"%git clone https://github.com/timsnow/advanced_sas_training_course\n",
"%cd 'advanced_sas_training_course/03 - SAS Software'"
]
},
Expand Down
10 changes: 5 additions & 5 deletions 03 - SAS Software/03 - Exercises and Answers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
"metadata": {},
"outputs": [],
"source": [
"!pip install bumps\n",
"!pip install numpy\n",
"!pip install sasmodels\n",
"!pip install matplotlib\n",
"%pip install bumps\n",
"%pip install numpy\n",
"%pip install sasmodels\n",
"%pip install matplotlib\n",
"\n",
"!git clone https://github.com/timsnow/advanced_sas_training_course\n",
"%git clone https://github.com/timsnow/advanced_sas_training_course\n",
"%cd 'advanced_sas_training_course/03 - SAS Software'"
]
},
Expand Down

0 comments on commit 9abddf9

Please sign in to comment.