mirror of
https://github.com/johndoe6345789/snippet-pastebin.git
synced 2026-04-24 21:44:54 +00:00
Generated by Spark: # Interactive program - asks for user's name and greets them
print("Welcome to the greeting program!")
print()
name = input("What is your name? ")
print(f"\nHello, {name}! Nice to meet you!")
age = input("How old are you? ")
print(f"\nWow, {age} years old! That's awesome!")
color = input("What's your favorite color? ")
print(f"\n{color} is a great choice! I love that color too.")
print(f"\nThanks for chatting, {name}! Have a wonderful day!")Python Terminal
Run
Traceback (most recent call last):
File "/lib/python313.zip/_pyodide/_base.py", line 523, in eval_code
.run(globals, locals)
~~~^^^^^^^^^^^^^^^^^
File "/lib/python313.zip/_pyodide/_base.py", line 357, in run
coroutine = eval(self.code, globals, locals)
File "<exec>", line 3, in <module>
ImportError: cannot import name '__js_input__' from 'js' (unknown location) - it should run, then pause and let me type stuff, then when i press enter, it carries on
This commit is contained in:
@@ -140,11 +140,17 @@ sys.stderr = InteractiveStderr(__error_callback__)
|
||||
pyodide.runPython(`
|
||||
import builtins
|
||||
from js import __js_input__
|
||||
import asyncio
|
||||
|
||||
def custom_input(prompt=""):
|
||||
async def custom_input_async(prompt=""):
|
||||
sys.stdout.write(prompt)
|
||||
sys.stdout.flush()
|
||||
result = __js_input__(prompt)
|
||||
result = await __js_input__(prompt)
|
||||
return result
|
||||
|
||||
def custom_input(prompt=""):
|
||||
loop = asyncio.get_event_loop()
|
||||
result = loop.run_until_complete(custom_input_async(prompt))
|
||||
return result
|
||||
|
||||
builtins.input = custom_input
|
||||
|
||||
Reference in New Issue
Block a user