Benutzer-Werkzeuge

Webseiten-Werkzeuge


python

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen RevisionVorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
python [2024-07-28 09:31:23] davidpython [2024-07-28 10:02:24] (aktuell) – [venv] david
Zeile 18: Zeile 18:
  
 relevante python pakete in debian relevante python pakete in debian
 +
 <code bash> <code bash>
 sudo apt install python-is-python3 python3 python3-pip python3-venv pipx sudo apt install python-is-python3 python3 python3-pip python3-venv pipx
Zeile 24: Zeile 25:
 paket mit pipx installieren paket mit pipx installieren
 (black ist übrigens ein super python formatter, es ist sowas wie das gofmt von python) (black ist übrigens ein super python formatter, es ist sowas wie das gofmt von python)
 +
 <code bash> <code bash>
 pipx install black pipx install black
Zeile 29: Zeile 31:
  
 venv erstellen venv erstellen
 +
 <code bash> <code bash>
 mkdir /tmp/python-venv-demo mkdir /tmp/python-venv-demo
Zeile 35: Zeile 38:
 type python type python
  
-python -m venv venv +python -m venv .venv 
-. venv/bin/activate+.venv/bin/activate
  
 type python type python
Zeile 47: Zeile 50:
  
 type python type python
 +</code>
 +
 +
 +===== best practices =====
 +
 +sicherstellen, dass der main code nur ausgeführt wird, wenn die datei als programm ausgeführt wird, nicht wenn sie als modul importiert wird (das macht der ''%%__name__ == "__main__"%%'' check)
 +
 +<code python main.py>
 +#!/usr/bin/env python3
 +
 +def main():
 +    print("Hello World!")
 +
 +if __name__ == "__main__":
 +    main()
 </code> </code>
  
/home/http/wiki/data/attic/python.1722159083.txt · Zuletzt geändert: von david