[Pythonmac-SIG] CF module oddity

Jack Jansen Jack.Jansen@cwi.nl
Tue May 6 10:35:26 EDT 2003


On Monday, May 5, 2003, at 22:35 Europe/Amsterdam, Ronald Oussoren 
wrote:

> I've been playing with the Carbon.CF module, mostly because I want to 
> add "toll-free" bridgeing to a future version of PyObjC. I noticed 
> something strange:
>
> >>> import Carbon.CF
> >>> s = Carbon.CF.CFStringCreateWithCharacters("hello")
> >>> s.toPython()
> u'\u6865\u6c6c'
> >>>
>
> Is this intentional? Using u"hello" instead of "hello" gives a better 
> result.

This is a feature. It is not a feature which I agree with (far from 
it:-), but a feature nonetheless.

CFStringCreateWithCharacters expects a unicode string. The Python 
format specifier for unicode strings accepts "normal" strings, and 
interpretes them as a binary data stream containing UTF16 unicode data.

CFStringCreateWithCString() does what you want, as does the simpler 
toCF(), which will
convert most Python datatypes to the equivalent CF representation.
--
Jack Jansen, <Jack.Jansen@cwi.nl>, http://www.cwi.nl/~jack
If I can't dance I don't want to be part of your revolution -- Emma 
Goldman





More information about the Pythonmac-SIG mailing list