[Tutor] (no subject)

Joel Goldstick joel.goldstick at gmail.com
Tue Jun 19 21:59:12 CEST 2012


On Tue, Jun 19, 2012 at 3:35 PM, Selby Rowley-Cannon
<selbyrowleycannon at ymail.com> wrote:
> 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?
> Thanks,
>         -Selby
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
try:
  print(Edictionary[Eword]
except KeyError:
  print Eword, " has not yet been translated"

If you catch the exception you can print a useful message.  Not sure
what that would be but I took a stab


-- 
Joel Goldstick


More information about the Tutor mailing list