[Pythonmac-SIG] CF module oddity

Ronald Oussoren oussoren@cistron.nl
Tue May 6 17:27:23 EDT 2003


On Tuesday, May 6, 2003, at 11:35 Europe/Amsterdam, Jack Jansen wrote:

>
> 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.

Very usefull :-( Is this documented anywhere? The documentation in the 
section "Extracting Parameters in Extension Functions" of "Extending 
and Embedding the Python Interpreter" does note mention this misfeature.

Ronald





More information about the Pythonmac-SIG mailing list