Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| modul:m323:learningunits:lu05:decorator [2024/03/28 14:07] – angelegt - Externe Bearbeitung 127.0.0.1 | modul:m323:learningunits:lu05:decorator [2025/12/17 13:28] (aktuell) – [Syntax] kmaurizi | ||
|---|---|---|---|
| Zeile 9: | Zeile 9: | ||
| ==== Syntax ==== | ==== Syntax ==== | ||
| - | Die grundlegende Syntax für einen Decorator in Python ist die folgende: | ||
| + | <WRAP group> | ||
| + | <WRAP half column> | ||
| + | Die grundlegende Syntax für einen Decorator in Python ist die folgende: | ||
| <code python> | <code python> | ||
| def decorator_function(original_function): | def decorator_function(original_function): | ||
| Zeile 22: | Zeile 24: | ||
| def display(): | def display(): | ||
| print(" | print(" | ||
| + | |||
| + | display() | ||
| + | </ | ||
| + | |||
| + | <WRAP half column> | ||
| + | Semantisch ist '' | ||
| + | <code python> | ||
| + | def decorator_function(original_function): | ||
| + | def wrapper_function(): | ||
| + | # zusätzliche Funktionalitäten hier | ||
| + | original_function() | ||
| + | # weitere zusätzliche Funktionalitäten | ||
| + | return wrapper_function | ||
| + | |||
| + | def display(): | ||
| + | print(" | ||
| + | |||
| + | # das macht @decorator_function: | ||
| + | display = decorator_function(display) | ||
| display() | display() | ||
| </ | </ | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | |||
| In diesem Beispiel ist '' | In diesem Beispiel ist '' | ||