This allows the variables to be accessed from inside local function definitions. It also reduces the potential conflict with the python script to a single global variable.
For example:
fn main() {
let data = vec![(4, 3), (2, 8), (3, 1), (4, 0)];
python! {
import matplotlib.pyplot as plt
def foo():
plt.plot('data)
plt.show()
foo()
}
}
Without this PR, that results in:
Traceback (most recent call last):
File "inline-python-example/src/main.rs", line 12, in <module>
foo()
File "inline-python-example/src/main.rs", line 10, in foo
plt.plot('data)
NameError: name 'plt' is not defined
thread 'main' panicked at 'python!{...} failed to execute', inline-python-example/src/main.rs:7:2
With the PR, it works as expected. Weirdly, it's not complaining about _rust_data but about plt. Not sure why that happens to be honest. It seems to be "fixed" by passing null as locals to PyEval_EvalCode.
This allows the variables to be accessed from inside local function definitions. It also reduces the potential conflict with the python script to a single global variable.
For example:
Without this PR, that results in:
With the PR, it works as expected. Weirdly, it's not complaining about
_rust_data
but aboutplt
. Not sure why that happens to be honest. It seems to be "fixed" by passing null as locals toPyEval_EvalCode
.