On Apr 21, 7:28 pm, R Wood <[EMAIL PROTECTED]> wrote: > To me this was a natural task for Perl. Turns out however, there's a catch. > Apple exports the file in UTF-16 to ensure anyone with Chinese characters in > their addressbook gets a legitimate Vcard file.
Here's a function that, given a `str` containing a vcard in some encoding, guesses the encoding and returns a canonical representation as a `unicode` object. def fix_encoding(s): m = u'BEGIN:VCARD' for c in ('ascii', 'utf_16_be', 'utf_16_le', 'utf_8'): try: u = unicode(s, c) except UnicodeDecodeError: continue if m in u: return u return None -- http://mail.python.org/mailman/listinfo/python-list