-
Notifications
You must be signed in to change notification settings - Fork 151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
error when using \n in python script #554
Comments
I tried seperating test_str into like test_str = "bar" + "\n" + "foo"; and replace \n with \\n, so the final codeStr in interp.eval(codeStr) is like
not like
But in some scenarios such as test_str.split("\n") in python, it didn't work. The return is not like ["foo", "bar"] but ["foo\nbar"] |
When you use interpreter.exec("test_str = 'one\\ntwo'");
interpreter.exec("print(test_str.split('\\n'))"); I admit that is quite confusing, I would recommend avoiding passing complex strings directly to interpreter.set("test_str", "one\ntwo");
interpreter.set("delim", '\n');
interpreter.exec("print(test_str.split(delim))"); It's also worth noting that this problem is not unique to jep, if you attempt to do the same thing using the python interpreter to run the python builtin >>> exec("test_str='one\ntwo'")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1
test_str='one
^
SyntaxError: unterminated string literal (detected at line 1)
>>> exec("test_str='one\\ntwo'")
>>> exec("print(test_str.split('\n'))")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1
print(test_str.split('
^
SyntaxError: unterminated string literal (detected at line 1)
>>> exec("print(test_str.split('\\n'))")
['one', 'two'] |
Describe the bug
When I use \n in python code, it seems to get confused with python's own indent newlines, resulting in an error.
To Reproduce
execute the followding code in JEP java.
I used interp.eval(codeStr) passing these code to jep, and used interp.invoke("mainFunction", new Object[] {inputs}); execute the python.
jep returned a exception:
jep.JepException:('unterminated string literal...)...
Environment (please complete the following information):
Additional context
I tried to replace \n in java env before passing it to python env, such as new_line = "\n", then concatenate it with other python strings. But I still got errors in some scenarios such as regular expression. How can I use \n avoiding confusion.
The text was updated successfully, but these errors were encountered: