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
No Python output if console.log() is called after Python code #712
Comments
Ok, it doesn't happen if I use:
|
Edit: I don't think this is coming from Pyodide :) |
Hi @marimeireles! It think this is actually expected (if unintuitive) behavior that I've tripped on a couple times. When the <py-script> tag evaluates, Pyscript calls pyodide's runPython/runPythonAsync, which are wrappers around Pyodide's eval_code() and eval_code_async() respectively. By default, This bit of code: from datetime import datetime
now = datetime.now()
now.strftime("%m/%d/%Y, %H:%M:%S") Therefore returns the date formatted as a string, which then gets written to the script's output element. If you Probably the clearer way for a programmer to achieve what this code does is to write the final line as I've run into this issue when my code ends with a function that I'm using for it's side effects that also returns a value, like <!-- index.html -->
<div id="parent"></div> # my_script.py
from js import document
p = document.createElement('p')
p.innerText = "Hello, world!"
document.getElementById("parent").appendChild(p) Shows up as: because Regardless, I think this is not terribly clear behavior. Maybe as part of #622, the behavior of <py-script> tags should no longer be to write the return value to the output element? It's really more of what a repl would do, printing the value of the last expression, rather than what I think of a script doing. |
Hey @JeffersGlass thanks for chiming in! |
Fixed by #749 |
Checklist
What happened?
Working on #622 I found a problem that I think it's coming from upstream
pyscript.py
.When you add a js print after python code that should be printing in the screen, nothing is printed. To reproduce try the following snippet:
The string "this is coming from js" shows up in the console normally, but the python output in the page remains empty.
E.g using the
hello_world
example, this is all I see in my screen:I'm exploring this, but feel free to add thoughts if you have any!
Thanks!
What browsers are you seeing the problem on? (if applicable)
Firefox, Chrome
Console info
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered: