Pyide
The pyide element represents a Python Integrated Development Environment (IDE) component.
It is used to embed a Python coding environment within the hyperbook website.
This element allows users to write, edit, and execute Python code directly in the browser.
:::pyide
```python
a = 5 + 2
print(a)
```
:::
You can also use any package listed here: https://pyodide.org/en/stable/usage/packages-in-pyodide.html
If you need packages from PyPI, use the packages attribute with a comma-separated list. Hyperbook loads micropip and installs these packages before executing your script.
:::pyide{packages="snowballstemmer"}
```python
import snowballstemmer
stemmer = snowballstemmer.stemmer("english")
print(stemmer.stemWords(["running", "runner", "runs"]))
```
:::
:::pyide
```python
import numpy as np
a = np.arange(15).reshape(3, 5)
print(a)
```
:::
Add test cases
You can add test cases to the code snippets by adding a test tag to the code block. The #SCRIPT# comment will be replaced by the written code. It can be placed in any part of the code block.
:::pyide
```python test
#SCRIPT#
r = check_palindrom("uhu")
if r:
print("Pass")
else:
print("Fail")
```
```python test
#SCRIPT#
r = check_palindrom("test")
if not r:
print("Pass")
else:
print("Fail")
```
```python
def check_palindrom(s):
return True
```
:::
When your code calls input(), the browser shows a prompt dialog for the value.
:::pyide
```python
a = input("Enter a value: ")
print(a)
```
:::
Stopping the execution
Use the Stop button in the editor to request an interrupt. For infinite loops or long-running processes, interruption is only reliable when these two headers are set on your server:
'Cross-Origin-Embedder-Policy': 'require-corp'
'Cross-Origin-Opener-Policy': 'same-origin'