Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cgi
- import cgitb
- cgitb.enable()
- print "Content-Type: text/html"
- print
- form= cgi.FieldStorage()
- try:
- lang1 = form["startlanguage"].value
- lang2 = form["finallanguage"].value
- word = form["word"].value
- if lang1 not in ("ita", "fra", "eng"):
- print "Wrong start language:", lang1
- elif lang2 not in ("ita", "fra", "eng"):
- print "Wrong final language:", lang2
- elif lang1 == lang2:
- print "The same languages:", lang1, lang2
- else:
- found = False
- tranlation = {}
- ita_eng = open("itafraeng.txt", "r")
- for row in ita_eng:
- word_ita, word_fra, word_eng = row.split()
- tranlation["ita"] = word_ita
- tranlation["fra"] = word_fra
- tranlation["eng"] = word_eng
- if word == tranlation[lang1]:
- found = True
- print '''<html>
- <body>
- <p>%s = %s</p>
- </body>
- <html>''' % (word, tranlation[lang2])
- break # exit `for` loop
- ita_eng.close()
- if not found:
- print "Word not found"
- except KeyError:
- print ' Error '
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement