I am new to PyScript and tried to create some script to create noise in a browser. But, of course, it is not working. The interface between javascript and python does not seem to work. Also, I cannot debug the python part. Having print statements, do not output anything anywhere.
However, the example code is in this repository:
Especially strange is that the waveform, generated by python, is not an array in javascript but a “proxy” (???) and I have no idea what this even means, save how to fix it.
Hi @alexander.dietz17 - is it possible that GitHub repository is private? Trying to access it gives me a 404: Not Found Error
If it is, and if you don’t want to make it public (totally fine), would you copy/paste some code here into a code block that we can look at?
In the meantime, a quick note on Proxy’s - in Pyodide (the runtime underlying PyScript, usually), when you access a Python object in JavaScript or a JavaScript object in Python, the object is wrapped in a “Proxy” which allows it to interoperate in its new language. For example, if you reference a Python dict in JS and attempt to usex.get('foo')
, the proxy handles translating that to x[foo]
in Python, so that item lookup still works.
Where this breaks down, as you’ve seen, is in logging. console.log
logs the literal object it sees (the proxy) not the underlying object.
To explicitly convert an object from a Python object to a JavaScript object (not a Proxy), you can use either toJS (in javascript) or to_js in python.
Hopefully we can provide more direct responses once we can see your code. And welcome to the PyScript nucleus!
1 Like