Published
Edited
May 14, 2019
Insert cell
Insert cell
import {py} from "@andrzejq/pnlib-brython-python-source"
Insert cell
{
// wait for div0 cell to be evaluated
div0;
// python code won't work until the referenced elements are appended to the DOM
py`
print('\n Brython: (re)evaluating cell')
from browser import document
print('\n __BRYTHON__',__BRYTHON__.__MAGIC__,'\n','-'*17,'\n')
def test(x, pattern):
print(f'''{x!r}''')
assert x == pattern, f'''{x!r} != {pattern!r}'''
test(f'''{1.23e-10:1.6}''', '1.23e-10') #py3:'1.23e-10'; brython(3.7.1):'1.23000e-1'
test(f'''{1.24e-10:1.15}''', '1.24e-10') #py3:'1.24e-10'; brython(3.7.1):'1.24000000000000e-1'

def echo(ev):
s = document["zone"].value
document["echo2"].text = f'Hello {s} !'
print(f'~ {s} ~')

btn = document["test"]; btn.unbind("click") # unbind, so re-evaluating this cell will be OK
btn.bind("click", echo)
`
return 'Brython test: btn.bind("click", echo) - this line is just a comment in observablehq'
}
Insert cell
div0 = {
return html`<p>Your name is : <input id="zone" autocomplete="off" value="Test 0">
<button id="test">click !</button> <span id="echo2"><span>
`;
}
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more