Menu

Accentuated Characters in pythonqt

Help
2015-06-04
2015-06-07
  • Emmanuel Nicolas

    Hi,

    I want to send paths from C++ to python, and for this I need to be able to transfer some strings from the main C++ code to the python script. However, I am having trouble with accentuated characters:

    If I execute this code:

    pythonModule.evalScript(QString("print('Téléchargements')"));
    

    Then I get the following output from python:

    File "<string>", line 1:
    SyntaxError: (unicode error) 'utf-8' codec can't decode byte 0xe9 in position 0: unexpected end of data
    

    Any idea as to how I could transfer those accentuated characters?

     

    Last edit: Emmanuel Nicolas 2015-06-04
  • Emmanuel Nicolas

    I found that this is actually also the case in the PyScriptingConsole example: if you type print('é') in the command line, you end up with the same unicode error.

     

    Last edit: Emmanuel Nicolas 2015-06-06
  • Emmanuel Nicolas

    Further testing:

    If I am doing print('é') from a py file that I evaluate, no problem upon calling the function.

    When doing

    QString e = QString::fromUtf8("é");
    pythonModule.evalScript(QString("print(%1)").arg(e));

    I get the error message:
    print(�)
    SyntaxError: invalid character in identifier

    But doing:

    pythonModule.evalScript("print('é')");
    pythonModule.evalScript("print('\u00e9')");

    I still get:
    SyntaxError: (unicode error) 'utf-8' codec can't decode byte 0xe9 in position 0: unexpected end of data

    Typing all these possibilities straight in python console perfectly works, so I assume it is an encoding problem. Any ideas?

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.