Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork320
String from print() comes as Unicode while from raise Exception() as AnsiString#465
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
I have Unicode file sample.py with the following script inside:
In IO UnicodeIO is set to True. In OnSendUnicodeData() I simply dump all received messages into a text file. That's how it looks when I run the script: Some of the data comes in incorrect encoding. Any ideas how to solve this? |
BetaWas this translation helpful?Give feedback.
All reactions
I have not tested but you need to specify a UTF8 encoding in
Script.LoadFromFile(aFileName);
and
TInputOutputStub.Output.SaveToFile('c:\Devel\tmp\PythonSample\sample.out')
Replies: 8 comments 14 replies
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
When I run your code with Demo01 I works well. I used
sample.py is utf8 encoded. Could you post a simple project in a zip file that reproduces the issue? |
BetaWas this translation helpful?Give feedback.
All reactions
-
Here. |
BetaWas this translation helpful?Give feedback.
All reactions
-
The script should be in the file and the script file name should be passed to the ExecStrings method as a parameter to reproduce the mistake. |
BetaWas this translation helpful?Give feedback.
All reactions
-
I have not tested but you need to specify a UTF8 encoding in Script.LoadFromFile(aFileName); and TInputOutputStub.Output.SaveToFile('c:\Devel\tmp\PythonSample\sample.out') |
BetaWas this translation helpful?Give feedback.
All reactions
-
When I specify the encoding in LoadFromFile, the following lines disappear from the output (which is really weird), and hence there is no encoding problem, not because the problem is solved, but because there is no line where the problem appeared previously.
|
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Here it works fine with:
sample,out
|
BetaWas this translation helpful?Give feedback.
All reactions
-
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
This line does not come up in either IDLE or when you run the script with python The output I am getting is identical to that of IDLE and python. |
BetaWas this translation helpful?Give feedback.
All reactions
-
Yes, but if you remove encoding, this line appears and it shows the exact cause of the exception. |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
the code you run is not the code you indent to run. The code you indent to run produces the output without that line. |
BetaWas this translation helpful?Give feedback.
All reactions
-
Did you try running the sample project without specifying the encoding? |
BetaWas this translation helpful?Give feedback.
All reactions
-
Yes. And if you inspect Script.Text you will see it is wrong. |
BetaWas this translation helpful?Give feedback.
All reactions
-
You get that line in other cases e,g, sample.py sample.out
|
BetaWas this translation helpful?Give feedback.
All reactions
-
Why don't you try it? |
BetaWas this translation helpful?Give feedback.
All reactions
-
As I understand we receive different results in some cases. |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Not if you encode your files. Python expects and uses utf8 encoding, In any case this is not a P4D issue. |
BetaWas this translation helpful?Give feedback.
All reactions
-
But since you asked: sample.out
|
BetaWas this translation helpful?Give feedback.
All reactions
-
BetaWas this translation helpful?Give feedback.
All reactions
-
The last thing.
|
BetaWas this translation helpful?Give feedback.
All reactions
👍 1
-
Done. |
BetaWas this translation helpful?Give feedback.