add processing words into a dictionary instead of just printing them, added comments
This commit is contained in:
17
Kapitel 6/6-2_daten_aus_einer_datei_lesen.py
Normal file
17
Kapitel 6/6-2_daten_aus_einer_datei_lesen.py
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
# leeres Dictionary anlegen
|
||||||
|
woerter = {}
|
||||||
|
|
||||||
|
# Datei lesend öffnen
|
||||||
|
fobj = open("woerterbuch.txt","r")
|
||||||
|
|
||||||
|
#Schleife welche aus Datei zeilenweise liest bis zum erreichen von EOF
|
||||||
|
for line in fobj:
|
||||||
|
|
||||||
|
# zeilen lesen und aufteilen in die variable zuordnung, zum aufteilen " " nutzen
|
||||||
|
zuordnung = line.split(" ")
|
||||||
|
|
||||||
|
#Dictionary woerter mit den aufgeteilten Werten füllen
|
||||||
|
woerter[zuordnung[0]] = zuordnung[1]
|
||||||
|
|
||||||
|
#sobald alle werte im Dictionary woerter abgelegt sind, Datei schließen
|
||||||
|
fobj.close()
|
||||||
Reference in New Issue
Block a user