From 956a7ab791ebbdb64549dd04e51586f9e0a67d4e Mon Sep 17 00:00:00 2001 From: Robert Haase Date: Tue, 2 Jul 2024 21:34:42 +0200 Subject: [PATCH] shortened import notebook --- .../02_python_basics/10_Import_packages.ipynb | 98 ++----------------- 1 file changed, 10 insertions(+), 88 deletions(-) diff --git a/docs/02_python_basics/10_Import_packages.ipynb b/docs/02_python_basics/10_Import_packages.ipynb index 894734252..1e19c6877 100644 --- a/docs/02_python_basics/10_Import_packages.ipynb +++ b/docs/02_python_basics/10_Import_packages.ipynb @@ -236,54 +236,7 @@ "id": "23644840-840f-4ecd-b09a-4fee262678ce", "metadata": {}, "source": [ - "Of course in this case, unless we find the specfiic line where the function is imported, we don't know that ```cos``` necessarily belongs to Numpy as we could also have defined such a function in the notebook. If we want to import **all** functions from a package we can also use the ```*``` sign:" - ] - }, - { - "cell_type": "code", - "execution_count": 21, - "id": "5809f8eb-1a81-46d5-aaff-11c9e672ef47", - "metadata": {}, - "outputs": [], - "source": [ - "from numpy import *" - ] - }, - { - "cell_type": "markdown", - "id": "a708b3c9-08d6-4dc9-a902-fc996e0ea1c7", - "metadata": {}, - "source": [ - "Here we have for example access to the sine function withouth having explicitly imported it:" - ] - }, - { - "cell_type": "code", - "execution_count": 22, - "id": "79ddc559-52ac-4cc2-acaf-19d2ccc3c4a6", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "0.0015926529164868282" - ] - }, - "execution_count": 22, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "sin(3.14)" - ] - }, - { - "cell_type": "markdown", - "id": "7461b9f0-c58e-4b31-8cc4-cf0dd15069c6", - "metadata": {}, - "source": [ - "As you can see, with this solution we have *no idea* what we actually imported in our notebook, which can lead to unwanted effects like re-using a function name. **If you don't have a specific reason to use this import variant, we strongly discourage its use.**" + "Of course in this case, unless we find the specfiic line where the function is imported, we don't know that ```cos``` necessarily belongs to Numpy as we could also have defined such a function in the notebook." ] }, { @@ -397,45 +350,6 @@ "normal()" ] }, - { - "cell_type": "markdown", - "id": "af135b70-e8a0-4d33-8f05-885ddc6855b5", - "metadata": {}, - "source": [ - "Finally we can rename using the ```as``` statement:" - ] - }, - { - "cell_type": "code", - "execution_count": 36, - "id": "ef43be12-dc16-4b52-a009-72bf4d798c8e", - "metadata": {}, - "outputs": [], - "source": [ - "from numpy import random as rd" - ] - }, - { - "cell_type": "code", - "execution_count": 37, - "id": "7988aa15-b136-4f58-a553-29ccfa9a9634", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "-0.6781586087709578" - ] - }, - "execution_count": 37, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "rd.normal()" - ] - }, { "cell_type": "markdown", "id": "cc770a20-0014-4b6c-b12e-3fa6b1d72f22", @@ -448,6 +362,14 @@ "- import just the ```norm``` function and call it\n", " " ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "72dc7b73-b072-411d-92f3-a7c9cce4395f", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -466,7 +388,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.13" + "version": "3.9.19" } }, "nbformat": 4,