Generated by Spark: It's supposed to accept interactive real time input, instead I get Welcome to the greeting program!

What is your name?
Traceback (most recent call last):
  File "<exec>", line 9, in custom_input_async
ImportError: cannot import name '__js_input__' from 'js' (unknown location)
Traceback (most recent call last):
  File "/lib/python313.zip/_pyodide/_base.py", line 597, in eval_code_async
    await CodeRunner(
    ...<9 lines>...
    .run_async(globals, locals)
  File "/lib/python313.zip/_pyodide/_base.py", line 411, in run_async
    coroutine = eval(self.code, globals, locals)
  File "<exec>", line 6, in <module>
  File "<exec>", line 16, in custom_input
  File "/lib/python313.zip/pyodide/webloop.py", line 369, in run_until_complete
    return run_sync(future)
  File "<exec>", line 9, in custom_input_async
ImportError: cannot import name '__js_input__' from 'js' (unknown location)
This commit is contained in:
2026-01-17 19:52:22 +00:00
committed by GitHub
parent 031ca48ee5
commit 9002991d85

View File

@@ -135,24 +135,18 @@ sys.stderr = InteractiveStderr(__error_callback__)
return ''
}
pyodide.globals.set('__js_input__', customInput)
pyodide.globals.set('js_input_handler', customInput)
pyodide.runPython(`
await pyodide.runPythonAsync(`
import builtins
import asyncio
from pyodide.ffi import to_js
async def custom_input_async(prompt=""):
async def custom_input(prompt=""):
import sys
sys.stdout.write(prompt)
sys.stdout.flush()
from js import __js_input__
result = await __js_input__(prompt)
return result
def custom_input(prompt=""):
import asyncio
loop = asyncio.get_event_loop()
result = loop.run_until_complete(custom_input_async(prompt))
result = await js_input_handler(prompt)
return result
builtins.input = custom_input