Skip to content

Instantly share code, notes, and snippets.

@horstjens
Last active November 10, 2025 12:23
Show Gist options
  • Select an option

  • Save horstjens/947188ab48389cecb719fe10c4b8c69c to your computer and use it in GitHub Desktop.

Select an option

Save horstjens/947188ab48389cecb719fe10c4b8c69c to your computer and use it in GitHub Desktop.
termin 09
import os # operation system
#https://docs.python.org/3/library/os.html
# os.path.join
# zugriff auf datei "rex.jpg" im Ordner "Hund":
# unter linux und macOS: folder/file
# unter windows: folder\file
# os.path.join wählt immer das richtige Verbindungszeichen
dateiname = os.path.join("Hund", "rex.jpg")
# os.name .. zeight betriebssystem an
print("Betriebsystem:", os.name)
# os.getcwd() ... zeigt current work directory
print(os.getcwd())
# os.walk ... durchsucht (rekursiv!) dateien und ordner
#for root, dirs, files in os.walk('.'):
# #print(root, dirs, files)
# print("============================")
# print("derzeit:", root)
# print("=============================")
# print("---- (unter)verzeichnisse: ----")
# for d in dirs:
# print(d)
# print("----- Dateien ----")
# for file in files:
# print(file)
# input("bitte enter drücken")
# pathlib
import pathlib
for root, dirs, files in pathlib.Path(".").walk():
print("======root ist: ===========================")
print(root)
print("===========================================")
print("---------- folders: ---------------")
for d in dirs:
print(d)
print("- - - - - - files - - - - - - - ")
for f in files:
print(f)
print("-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.")
input("Enter drücken")
# os.call ... ruft ein anderes Programm direkt vom Betriebssystem auf (z.B. calc.exe )
# bessere Alternative subprocess
import subprocess
subprocess.call("pluma") # started (im Labor) den Editor pluma
# sys ... System
import sys #https://docs.python.org/3/library/sys.html
# liste der argumente ... das erste argument ist immer der
# python-filename
# die elemente der Liste sind immer strings
# bsp: programm starten mit python termin09_001.py abc 123
print("sys.argv ist", sys.argv)
#sys.exit() # beendet ein programm sofort
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment