On 6/19/2012 12:35 PM Selby Rowley-Cannon said...
Mailing list;
I have a small, [for the most part] functioning translation app for
Rydish, a language created for the sole purpose of an RPG. The only
problem is when I enter a word that has not yet been translated, I get
this error:

Traceback (most recent call last):
File "translator.py", line 25, in <module>
Etranslate()
File "translator.py", line 14, in Etranslate
print(Edictionary[Eword])
KeyError: 'world'

Is there a way to print a user-freindly message instead of displaying a
traceback?

As you're writing a translator it may be interesting to swap in something that can still be used in the translation. No one's mentioned get as an option:

>>> Edict = dict(zip('abcde','ABCDE'))
>>> for ii in 'agbdteabcdfe':
...     print Edict.get(ii,'-grumble-')
...
A
-grumble-
B
D
-grumble-
E
A
B
C
D
-grumble-
E
>>>


Or spice it up!

>>> import random
>>> undefined = ['-grumble-','-mumble-','-garbled-','-cough-']

>>> for ii in 'agbdteabcdfe':
...     print Edict.get(ii,random.choice(undefined))
...
A
-mumble-
B
D
-grumble-
E
A
B
C
D
-cough-
E
>>>


Emile





_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to