From 101004be511b0823a3ac9d879a2bb6b1d5d920fa Mon Sep 17 00:00:00 2001 From: MuedeHydra Date: Wed, 12 Nov 2025 18:15:04 +0100 Subject: [PATCH] add modules --- src/python_wahlmodul.typ | 98 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 97 insertions(+), 1 deletion(-) diff --git a/src/python_wahlmodul.typ b/src/python_wahlmodul.typ index db614b9..9f3ba6f 100644 --- a/src/python_wahlmodul.typ +++ b/src/python_wahlmodul.typ @@ -258,7 +258,6 @@ match day: print("I love weekends!")```]) - === Schleifen ==== for-loop Alle Items werden ausgeprintet. @@ -322,6 +321,103 @@ Erklärung: - ```py return something ```: Falls etwas zurückgegeben werden möchte kann dies mitels return gemcht werden. Es ist auch möglich mehere variabeln zurückzugeben z.b. ```py f, p = return x, y ```. Falls nicht zurückgegeben werden möchte kann auf dass return verzichtet werden. Optionale Parameter kommen immer am schluss! +=== Module +#grid(columns: (1fr, 1fr),[ +Um die Funktionen im *main.py* nutzen zu können gibt es vier mehtoden um die funktionen ui Importieren. Hier Beispiel mit *functions.py*. +], [ +*functions.py* +#table(columns: 1fr, [```py +def function_a () : + pass +def function_b () : + pass +def function_c () : + pass +```]) +]) +#table(columns: (0.5fr, 1fr), +[Nur die notwendigen Funktionen Importieren], [```py +from functions import function_a, function_b +print(function_a()) +```], +[Nur das Modul Importieren], [```py +import functions +print(functions.function_a()) +```], +[Alle Funktionen Importieren \ *nicht empfohlen!*], [```py +from functions import * +print(function_a ()) +```], +[Modul als Alias Importieren], [```py +import pandas as pd +pd.read_csv() +```], +[Funktion als Alias Importieren], [```py +from functions import function_a as a +print(a()) +```], +) +==== Bekannte Module +- *pandas*: powerful Python data analysis toolkit +- *numpy*: NumPy is the fundamental package for scientific computing with Python +- *scikit-learn*: A set of python modules for machine learning and data mining +- *plotly*: An open-source, interactive data visualization library for Python +- *matplotlib*: A library for creating static, animated, and interactive visualizations in Python. + +==== Autostart beim import +*ACHTUNG*: Module werden beim Import in einem anderen Modul ausgeführt! +#grid(columns: (1fr, 1fr, 0.8fr), gutter: 10pt,[ + *main.py* + #table(columns: 1fr, [```py + import my_functions + name = "Marco" + print_hallo(name) + ```]) +], [ + *my_functions.py* + #table(columns: 1fr, [```py + def print_hallo(name): + print(f"{name}") + print_hallo("Marco") + ```]) +], [ + *Output* + #table(columns: 1fr, [```py + "Marco" + "Marco" + ```]) +]) +Um dieses Verhalten zu unterdrücken, muss der code mit der folgenden Zeile ergänzt werden. + #table(columns: 1fr, [```py +if __name__ == "__main__": + pass +```]) +#grid(columns: (1fr, 1fr, 0.8fr), gutter: 10pt,[ + *main.py* + #table(columns: 1fr, [```py + import my_functions + name = "Marco" + print_hallo(name) + ```]) +], [ + *my_functions.py* + #table(columns: 1fr, [```py + def print_hallo(name): + print(f"{name}") + if __name__ == "__main__": + print_hallo("Marco") + ```]) +], [ + *Output* + #table(columns: 1fr, [```py + "Marco" + ```]) +]) + +=== Daten Lese und Schreiben +==== csv +==== json + === Runden