I'm trying to add a python terminal onto a website using pyscript to run programs I've written using
<script type="mpy" terminal worker src="subrepo/folder/program.py"></script>
The terminal does appear, and it does run the first part of the code, put after the first input, it doesn't run.
This is the code I'm trying to run in the terminal.
#importing fuctions
from functionsource1 import function1
from functionsource2 import function2
#giving user choice between which fuction to run
choice = int(input("Choose to function1 or function2. Enter 1 to function1. Enter 2 to function2. "))
if choice == 1:
print("debug test")
function1()
elif choice == 2:
print("debug test")
function2()
else:
print("ERROR")
After the code takes the input, nothing else runs, including the debug prints. I don't know what's wrong.
For clarification, here's the full html file.
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>Portfolio</title>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@pyscript/core/dist/core.css">
<script type="module" src="https://cdn.jsdelivr.net/npm/@pyscript/core/dist/core.js"></script>
<mpy-config>
[files]
"./subrepo/folder/function1.py" = "function1.py"
"./subrepo/folder/function2.py" = "function2.py"
</mpy-config>
</head>
<body>
<h1>Portfolio</h1>
<p>
My name is ---. I'll be putting any work I've done here for the time being. I'll update the site when I have something worthwhile to put here.
</p>
<script type="mpy" terminal worker src="subrepo/folder/program.py"></script>
</body>
</html>
I'm working on a github codespace, if that affects anything.
<script type="mpy">...code...</script>or it needs to accessmyterm = document.querySelector("#my_script");and run code asawait myterm.process('print("Hello world!")');but I don't see it in your code.... = "functionsource1.py"instead of... = "function1.py", etc/) I can run it and inDevToolsI see errorFile "<stdin>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'terminal'. Maybe it bug in module or maybe it needs something else in HTMLimport codecode.interact()to have interactive Python and it seems it has problem with keyEnterininput(). When I pressEnterthen it still waits for more. When I press againEnterthen it endsinput()but it assign something like this<JsProxy14>to variablesworker. And theninput()shows popup window.