Support for accessing Python scope
According to pyodide runPython can return a value https://pyodide.org/en/stable/usage/quickstart.html?highlight=expression#running-python-code I was looking to the code and I see that you wrap the run call into an exec method which is part of the problem here. Right now I don't really understand why this wrapper is here and I assume that's because I'm pretty new to the python engine. In an other hand I don't see how to get anything else then stdout and/or stderr with this hook.
I'll be happy to contribute if you think that could be a great enhancement to get the result of code execution and/or share some variables like globals for exemple.
Hi, are you asking why the runPython function doesn't return a value? If so I'm happy to explain this further.
We're always looking to improve the API to make it more useful, so suggestions are certainly welcome.
Currently, there isn't support for directly accessing the Python scope (i.e. globals) from JavaScript, or vice versa. Ideally, I'd like to support this behaviour but due to using web workers to run the Pyodide instances, this is tricky to get working.
My first question is why are you using python's exec function instead of a direct execution. Then I would like to use this hook to run a python script that computes a value and use this value in javascript. If you have some idea on the way to add this I can contribute in that way :)
To answer your first question, every execution is wrapped in some additional Python code to improve the default error handling behaviour.
Getting the value of variables directly from Python (other than from stdout) is currently unsupported, so I'm unable to provide any examples of this just yet. We're looking into supporting access to globals, so once I have more to share I'll update this issue with further information.
ok, thank you for your answer
Hi,
Very exciting project! I had initial success interoperating a React app with NumPy/SciPy for scientific computing. For now, the numerical array data in TS is passed to Python by embedding it in the Python script string, and the result from Python is passed back to TS through stdout. A smoother interoperation is crucial, and I am very much interested in the progress of this issue.
It seems that you have a PR on accessing the Python global scope hanging around for a while https://github.com/elilambnz/react-py/pull/71 What is holding back from merging this?
Thanks!
I have forked and added the feature of getting value from globals
To implement this, I removed the author-improved error handling, so it is just for anyone who needs to get variable values from globals. Besides, some advanced vars like functions in Python cannot be transmitted from the JS worker to the React Webpage.