mirror of
https://github.com/johndoe6345789/snippet-pastebin.git
synced 2026-04-24 13:34:55 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user