pyodide icon indicating copy to clipboard operation
pyodide copied to clipboard

dont use javascript prompt() for python input()

Open milahu opened this issue 5 months ago • 7 comments

🐛 Bug

python input() is implemented with javascript prompt()

To Reproduce

input()

import sys; sys.stdin.read(1)

Expected behavior

no javascript prompt() popup the input should be read by the terminal emulator (or from the stdin stream)

this is needed to create simple user input prompt apps

the user input should happen in the context of the terminal buffer not in a popup window that hides the terminal buffer

Environment

  • Pyodide Version: 0.28.0 at https://pyodide.org/en/stable/console.html
  • Browser version:137.0.7151.119
  • Any other relevant information:

Additional context

related: #2887 #1219

alternative: https://github.com/sagemathinc/cowasm

milahu avatar Jul 16 '25 06:07 milahu

You can use pyodide.setStdin() to configure this how you like. I'm not sure I'd consider it a bug, the alternative option would be to always raise an error or always return an empty string.

hoodmane avatar Jul 16 '25 06:07 hoodmane

docs: pyodide.setStdin

but this is not implemented in pyodide see also cowasm/docs/differences-from-pyodide.md#synchronous-input

milahu avatar Jul 16 '25 08:07 milahu

What is not implemented in Pyodide?

hoodmane avatar Jul 16 '25 09:07 hoodmane

https://cowasm.org/

>>> input()
asdf
'asdf'

... without a javascript prompt popup

milahu avatar Jul 16 '25 09:07 milahu

You can call pyodide.setStdin() and configure this in Pyodide to work how you like.

hoodmane avatar Jul 16 '25 10:07 hoodmane

how exactly? docs dont help

milahu avatar Jul 16 '25 12:07 milahu

Cowasm runs on WebWorker, if you want to make input work without blocking the main thread, you should do the same thing.

This video will help you understand what kind of things are required: https://youtu.be/-SggWFS15Do?si=SqfbhnpwHnmMn0Q1

ryanking13 avatar Jul 17 '25 08:07 ryanking13