-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Python code inputs #239
Comments
Just out of curiosity, is it advisable to use python's input type on a webpage? Shouldn't you use an HTML form for this? |
Well, considering It's python in the browser, I would like to think it should be a thing. Like it works... but not very well. Kinda scuffed mixed in with trying to learn html. It's probably not advisable but like I said..it is "python in the browser/html" after all. I would do the whole html form option but I don't currently know how to get the users input from that form into my python script as an argument to then output properly.... Also asking for input in my python script seems easier to handle/deal with than setting up everything for the form and making it look good, etc. |
Thank you for the report. It seems to be a pyodide issue. E.g., if you code to the pyodide online REPL:
See also pyodide/pyodide#2505 I think this is more or less what's happening:
In Pyscript, when you print something to stdout it is appended to the output div. This explains why you see I think this should be fixed by either upstream pyodide or pyscript itself. The easiest way is probably to provide our own implementation of the builtin |
Here is a partial workaround. Add this at the start of your Python scripts : The try/except is to patch input() only once in case you use a REPL. This will make input() behave more as expected in the console (prints prompt + value + new line). |
The reason for that is the asyncness nature of the browser that doesn't translate well to the python world. |
We solved the input issue in current terminal when it runs in workers and from a sync perspective there's nothing else one can do on the main thread because it has to be synchronous. The current PyScript terminal doesn't use the JS prompt and it works without surprises so I think we can close this. |
In my python script, When i ask for user input...It is very very weird. The following are some examples of what's happening when I ask for input.
Firstly;
Secondly;
Additionally;
Example Code;
html
python
Overwiew;
Asking for user input in a python script doesn't work to well and is a bit buggy.
The text was updated successfully, but these errors were encountered: