diff --git a/slides/input_output_slides.ipynb b/slides/input_output_slides.ipynb index 670cb577..1090945b 100644 --- a/slides/input_output_slides.ipynb +++ b/slides/input_output_slides.ipynb @@ -87,6 +87,30 @@ "print(f\"x is {x}\")" ] }, + { + "cell_type": "markdown", + "metadata": { + "slideshow": { + "slide_type": "fragment" + } + }, + "source": [ + "Likewise, we can put any *expression* in `{}`:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "slideshow": { + "slide_type": "fragment" + } + }, + "outputs": [], + "source": [ + "print(f\"x+1={x+1}\")" + ] + }, { "cell_type": "markdown", "metadata": { @@ -102,18 +126,19 @@ ] }, { - "cell_type": "code", - "execution_count": null, + "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, - "outputs": [], "source": [ + "\n", + "```python\n", "print(\"Enter your name\")\n", "name = input()\n", - "print(f\"Hello, {name}\")" + "print(f\"Hello, {name}\")\n", + "```" ] }, { @@ -184,8 +209,8 @@ "outputs": [], "source": [ "#With `/` we can combine paths:\n", - "\n", - "data_dir = (pl.Path(\"./tutorial/tests\") / pl.Path(\"./data\"))\n", + "import pathlib as pl\n", + "data_dir = (pl.Path(\"../tutorial/tests\") / pl.Path(\"./data\"))\n", "\n", "#With the pattern `\"*.csv\"` we look for all files that end in \".csv\"\n", "\n", @@ -227,7 +252,7 @@ }, "outputs": [], "source": [ - "input_file = open(pl.Path(\"./tutorial/tests/data/hello.txt\"))\n" + "input_file = open(pl.Path(\"../tutorial/tests/data/hello.txt\").resolve())\n" ] }, { @@ -270,7 +295,7 @@ }, "outputs": [], "source": [ - "input_file = open(pl.Path(\"./tutorial/tests/data/hello.txt\"))\n", + "input_file = open(pl.Path(\"../tutorial/tests/data/hello.txt\"))\n", "print(input_file.readlines())\n", "input_file.close()\n" ] @@ -309,7 +334,7 @@ "outputs": [], "source": [ "# `w` opens a file for writing\n", - "output_file = open(pl.Path(\"./tutorial/tests/data/me.txt\"), \"w\")\n" + "output_file = open(pl.Path(\"../tutorial/tests/data/me.txt\"), \"w\")\n" ] }, { @@ -360,7 +385,7 @@ }, "outputs": [], "source": [ - "input_file = open(pl.Path(\"./tutorial/tests/data/me.txt\"))\n", + "input_file = open(pl.Path(\"../tutorial/tests/data/me.txt\"))\n", "print(input_file.readlines())\n", "input_file.close()\n" ] @@ -431,9 +456,9 @@ "outputs": [], "source": [ "import pathlib as pl\n", - "with open(pl.Path(\"./tutorial/tests/data/hello.txt\")) as input_file:\n", + "with open(pl.Path(\"../tutorial/tests/data/hello.txt\")) as input_file:\n", " #This is the scope of the context manager.\n", - " #As long as we stay inside of this, we can acess `input_file`\n", + " #As long as we stay inside of this, we can access `input_file`\n", " text = input_file.readlines()" ] }, @@ -472,7 +497,10 @@ }, "outputs": [], "source": [ - "print(input_file.readlines())" + "try:\n", + " print(input_file.readlines())\n", + "except ValueError as e:\n", + " print(e)" ] } ], @@ -483,7 +511,15 @@ "name": "python3" }, "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", "version": "3.11.3" }, "orig_nbformat": 4, pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy