Christian Ergh wrote:

A smiple way to try out different encodings in a given order:

# -*- coding: latin-1 -*-

def get_encoded(st, encodings):
    "Returns an encoding that doesn't fail"
    for encoding in encodings:
        try:
            st_encoded = st.decode(encoding)
            return st_encoded, encoding
        except UnicodeError:
            pass


st = 'Test characters æøå ÆØÅ' encodings = ['utf-8', 'latin-1', 'ascii', ] print get_encoded(st, encodings)

    (u'Test characters \xe6\xf8\xe5 \xc6\xd8\xc5', 'latin-1')

--

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to