[1.1.0] java.lang.IllegalArgumentException: Cannot create PyString with non-byte value

Asked by Karl

I am using Windows 10 Pro.

Here is my code in Sikuli:
with open("C:\error_log", "a") as f:
    f.write(“Success")

Here is the Sikuli error:
[error] script [ my_second_test ]] stopped with error at line --unknown--
[error] Could not evaluate error source nor reason. Analyze StackTrace!
[error] java.lang.IllegalArgumentException: Cannot create PyString with non-byte value

I am using SikuliIDE 1.1.0 (2015-10-05_17:07)

How do I write to a file in Sikuli?

This question doesn't provide an answer:
https://answers.launchpad.net/sikuli/+question/268686

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

in Python strings the \ is an escape character and must be doubled if used as a real character:

with open("C:\\error_log", "a") as f:

an alternative is to use so called raw strings, where every character is real, but a \ must not be the last character:

with open(r"C:\error_log", "a") as f:

Revision history for this message
Karl (k-d) said :
#2

That doesn't fix the error.

Even this produces the error:
with open("error_log", "a") as f:
    f.write(“Success")

Revision history for this message
Karl (k-d) said :
#3
Revision history for this message
Best RaiMan (raimund-hocke) said :
#4

LOL, you must have eagle eyes, to see the problem:

f.write(“Success")

carefully look at the opening apostrophe: that is illegal!

so this should work:
f.write("Success")

... but I just realized, that in the IDE “Success" is not colored as a string - I have to admit: I did not see that either.

Revision history for this message
Karl (k-d) said :
#5

Thank you!