Python for Vcard Parsing in UTF16

R Wood rwood at therandymon.com
Fri Apr 20 22:07:44 EDT 2007


Alex Martelli wrote:

> R Wood <rwood at therandymon.com> wrote:
>    ...
>> alias Linus_Torvalds Linus Torvalds <lt at linux.com>
>> 
>> 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.  And of course Perl
>> somewhat
>> chokes on UTF.  
> 
> Sure, Python and Perl (and Ruby) should be equally suitable for the
> task, so, if Python appears more suitable by having built-in unicode
> capabilities, go for it.  I'm a bit uncertain about the UTF-16 export
> though; I know some applications do use it (e.g., Microsoft Entourage),
> but I thought Apple's Address Book didn't, and, having just tried a
> VCard export from mine, it looks quite ASCII to me.  Maybe you've set
> some kind of preference, or...?
> 
> 
> Alex

I did the same thing.  Apple's clever.  If your addressbook doesn't have any
higher characters, ie nothing but ASCII, it will export your addressbook in
ASCII.  But if you have anything else (in my case, Spanish, French, and
Italian) it goes for UTF16.  I first thought it was UTF8 but realized since
Apple supports all sorts of Asian languages really well they need UTF16 to
deal with it, and importing the exported file into Jedit using UTF16
encoding confirmed that's what it is.




More information about the Python-list mailing list