> On 10 Apr 2022, at 09:23, Ben Byram-Wigfield via Pythonmac-SIG > <pythonmac-sig@python.org> wrote: > > I'm converting a lot of python2 scripts that use pyobjc to python3, and > having trouble getting them to work. The problem seems to relate to the > Unicode changes in python3. > > Something as simple as supplying a string to method like this: > > provider = CGDataProviderCreateWithFilename(filename) > > gives: ValueError: depythonifying 'char', got 'str' of 1 > > I can get it to work if I encode the string first: > > filenameNonU = filename.encode('utf-8') > provider = CGDataProviderCreateWithFilename(filenameNonU)
This is the correct code pattern. PyObjC is a bit more strict here when running on Python 3: The C argument is a C string, which is represented as a bytes value in Python. In Python 2 the code also accepted unicode (str in Python 3), I removed that because Python 3 treats str and bytes differently. > > But that will only work for “ASCII” range characters. Any characters greater > than 128 gives: > > ValueError: depythonifying 'char', got 'int' of wrong magnitude That’s unexpected, could you file an issue about this on the PyObjC tracker? Ronald — Twitter / micro.blog: @ronaldoussoren Blog: https://blog.ronaldoussoren.net/
_______________________________________________ Pythonmac-SIG maillist - Pythonmac-SIG@python.org https://mail.python.org/mailman/listinfo/pythonmac-sig unsubscribe: https://mail.python.org/mailman/options/Pythonmac-SIG