Problem mit Wörterbuch
Verfasst: Samstag 26. April 2014, 15:34
Code: Alles auswählen
# -*- coding: utf-8 -*-
fobj = open("vokabeln.txt", "r")
fobj.close()
woerter = {}
fobj = open("vokabeln.txt", "r")
for line in fobj:
line = line.strip()
zuordnung = line.split("-")
woerter[zuordnung[0]] = zuordnung[1] #0 = Französisches Wort; 1 = Deutsches Wort
fobj.close()
while True:
wort = raw_input("Geben Sie ein Wort ein: ")
if wort in woerter:
print "Das deutsche Wort lautet:", woerter[wort]
else:
woerter = {}
fobj = open("vokabeln.txt", "r")
for line in fobj:
line = line.strip()
zuordnung = line.split("-")
woerter[zuordnung[1]] = zuordnung[0] #1 = Französisches Wort; 0 = Deutsches Wort
fobj.close()
if wort in woerter:
print "Das französische Wort lautet:", woerter[wort]
else:
print "Das Wort ist unbekannt."
Code: Alles auswählen
un site-eine Website
Code: Alles auswählen
Traceback (most recent call last):
File "vokabelabfrage.py", line 32, in <module>
for line in fobj:
ValueError: I/O operation on closed file
LG J4RVIS