Apr-16-2023, 12:13 PM
(This post was last modified: Apr-16-2023, 12:14 PM by pyscript_dude.)
Hi everyone,
I want to embed a python script into an html page by using pyscript. What I am trying is giving a sequence of integers as "1,2,3,4,5,6" and another integer "n" which divides the length of the sequence as inputs, the python script gives a matrix. Here is what I have tried:
I want to embed a python script into an html page by using pyscript. What I am trying is giving a sequence of integers as "1,2,3,4,5,6" and another integer "n" which divides the length of the sequence as inputs, the python script gives a matrix. Here is what I have tried:
<html>
<head>
<link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
<script defer src="https://pyscript.net/latest/pyscript.js"></script>
</head>
<body>
<input type="text" id="input_str"/>
<input type="number" id="n"/>
<button id="submit-button" type="button" py-click="my_function()">OK</button>
<div id="test-output"></div>
<p>Output:</p>
<p id='output'></p>
<py-config>
packages = ["numpy"]
</py-config>
<py-script>
import numpy as np
from pyscript import Element
def my_function():
input_str = Element('input.str').value
n = int(Element('n').value)
input_list = input_str.split(",")
w = []
for num in input_list:
w.append(int(num))
rows = len(w) // n
A = np.zeros((rows, n))
for i in range(len(w)):
if (w[i] % n == 0):
A[w[i]//n - 1, n-1] = int(i+1)
else:
A[w[i]//n, w[i]%n-1] = int(i+1)
result_place = Element('output')
result_place.write(str(A))
</py-script>
</body>
</html>The python script works well alone, however, it gives the following error when I try to compile the html file.Error:IndentationError: unindent does not match any outer indentation levelAny help would be appreciated to fix it.
