Jump to content
Registration disabled at the moment Read more... ×
Sign in to follow this  
Jacek Laskowski

PythonEngine.PyUnicode_FromString() issue

Recommended Posts

If the data variable contains any character outside the Latin alphabet, such as a Polish diacritical chars, the function returns nil

 

 data: AnsiString = 'ąęść';


  pObj := fPyEngine.PyUnicode_FromString(PAnsiChar(data)); <-- return nil
  fPyModule.SetVar('data', pObj); <-- then this raises an exception

How to properly pass diacritical chars in a string?

 

ps. the function has Unicode in its name, which means it should probably allow arbitrary characters

Edited by Jacek Laskowski

Share this post


Link to post

Why are you expecting ANSI encodings to be of use? Why aren't you using Unicode, either UTF8 or UTF16. 

 

I believe the function you call expects UTF8 which of course you are not passing. Then again I'm not sure why you picked on this function to make a string. 

Edited by David Heffernan
  • Like 1

Share this post


Link to post

P4D provides a function:

 

function TPythonEngine.PyUnicodeFromString(const AString : UnicodeString) : PPyObject;

  • Thanks 1

Share this post


Link to post
21 hours ago, David Heffernan said:

Why are you expecting ANSI encodings to be of use? Why aren't you using Unicode, either UTF8 or UTF16. 

 

I believe the function you call expects UTF8 which of course you are not passing. Then again I'm not sure why you picked on this function to make a string. 

I passed what the function expected:

 

    PyUnicode_FromString:function (s:PAnsiChar):PPyObject; cdecl;

 

Anyway, unfortunately the module has no documentation, so I also rely on examples from this forum, SO and demos in my experiments. I didn't know that there is a second analogous function with an almost identical name.

 

@pyscripter Thx

 

I am slowly learning, admittedly, the additional difficulty is the lack of knowledge of Python, but AI helps with this.

Edited by Jacek Laskowski

Share this post


Link to post
3 hours ago, Jacek Laskowski said:

unfortunately the module has no documentation

This is a Python API function which is documented. And the documentation states UTF8. You won't see encodings other than UTF8 and UTF16 in the API. 

Share this post


Link to post

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×