perchance schrieb:
> Anyone know a good way to transform latin 1 foreign characters from
> MySQL into UTF-8 for insertion into Postgres? I feel like I'm missing
> something obvious.
>
>   
You can handle this at python level like this:

byte_string='latin1-bytes'
unicode_string=byte_string.*decode*('latin1')

If you have latin1 and utf8 mixed, you can use this:

# the order of the encoding list is important
encoding_guess_list=['utf8', 'latin1']
def try_unicode(string, errors='strict'):
    if isinstance(string, unicode):
        return string
    for enc in encoding_guess_list:
        try:
            return string.decode(enc, errors)
        except UnicodeError, exc:
            continue
    raise UnicodeError('Failed to convert %r' % string)

HTH,
  Thomas

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to