Repeat an exception

Alf P. Steinbach alfps at
Thu Feb 4 04:00:45 CET 2010

* mf:
> I'm translating a db from english to spanish with the Google
> translator API. The problem is when a TranslationError occurs(usually
> because of connection problems). I can
> except the first one, but I don't know how to except again. I "solved"
> the problem by saving temp db's and then joining them, but it must be
> a pythonic way to do it.
> Here's a snippet from the code:
> english_field = oldDb[i].fieldData[0]           #oldDb is a db filled
> with english words

Is this actual code? I may be mistaken, but at least in Python 3.x it seems 
there should be a comma between each 'with' expression. And there should 
certainly be a colon at the end.

It's best to copy and paste real code.

Made-up code can just be misleading for those who'd like to help.

>     try:
>         spanish_field = translate(english_field, lang_to='es',
> lang_from='en')
>     except TranslationError:
>         spanish_field = translate(english_field, lang_to='es',
> lang_from='en')
> #Then I save the fields into a new db

Possibly I'm misunderstanding what you mean, but have you thought of using a loop?

Cheers & hth.,

- Alf

More information about the Python-list mailing list