[Vobject] saving unicode vcard
Jeffrey Harris
jeffrey at osafoundation.org
Sat May 31 15:25:57 CDT 2008
Hi Anil,
> I am reading some data from a database in UTF8. I convert the data
> into unicode. I want to save it to a vcard file. Should this data be
> written as Unicode or UTF8?
>
> I am doing something like this now:
>
> f = codecs.open(fname, "w", 'utf-8')
> f.write(j.serialize().decode('utf-8'))
> f.close()
I really need to tweak this, but right now, serialize *always* encodes
as utf-8, you don't have any choice in the matter.
Note that the serialize method can take a stream as an argument, in
which case it will serialize directly to the stream.
So what you're doing above should work, but it'd be simpler to just do:
f = open(fname, "w")
j.serialize(f)
That should put utf-8 encoded data in fname.
Yes, UTF-8 contains escape characters for data that isn't 7-bit ASCII.
All in all, I'm not sure what's going wrong for you.
Sincerely,
Jeffrey
More information about the VObject
mailing list