Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| — |
cowork:schulung:42:python_ucfile [2026/02/21 00:18] (aktuell) itbs angelegt |
||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| + | <code python uc.py> | ||
| + | import re | ||
| + | from pathlib import Path | ||
| + | folder = Path.cwd() | ||
| + | |||
| + | include_pattern = re.compile( | ||
| + | r'/ | ||
| + | re.DOTALL | ||
| + | ) | ||
| + | |||
| + | main_open = re.compile( | ||
| + | r'/ | ||
| + | re.DOTALL | ||
| + | ) | ||
| + | |||
| + | main_close = re.compile( | ||
| + | r' | ||
| + | re.DOTALL | ||
| + | ) | ||
| + | |||
| + | for c_file in folder.rglob(" | ||
| + | try: | ||
| + | text = c_file.read_text(encoding=" | ||
| + | except UnicodeDecodeError: | ||
| + | print(f" | ||
| + | continue | ||
| + | |||
| + | original = text | ||
| + | |||
| + | text = include_pattern.sub(r'# | ||
| + | text = main_open.sub(r' | ||
| + | text = main_close.sub(r' | ||
| + | |||
| + | if text != original: | ||
| + | c_file.write_text(text, | ||
| + | print(f" | ||
| + | |||
| + | print(" | ||
| + | </ | ||