-
Notifications
You must be signed in to change notification settings - Fork 134
Open
Description
I run this little snipped
let code_input = format!("def sum(a, b):\n return a + b");
let code_test = format!("\nresult = sum(1, 2)\nprint(result)",);
let code = format!(
r#"{}
{}"#,
code_input, code_test
);
let result: Result<PyObject, PyErr> = py.eval(&code, None, None);
println!("CODE: \n{}", code);
println!("OUTPUT: \n{result:#?}\n");And this is the result:
CODE:
def sum(a, b):
return a + b
result = sum(1, 2)
print(result)
OUTPUT:
Err(
PyErr {
ptype: <class 'SyntaxError'>,
pvalue: Some(
('invalid syntax', ('<string>', 1, 1, 'def sum(a, b):\n', 1, 4)),
),
ptraceback: None,
},
)
Where is the invalid syntax coming from?
if i copy paste the code into a python repl, it executes.
def sum(a, b):
return a + b
result = sum(1, 2)
print(result)Metadata
Metadata
Assignees
Labels
No labels