transpiling.py

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
"""
Example to demonstrate simple transpiling and evaluating.
"""

from flexx.pyscript import js, py2js, evaljs, evalpy

def foo(a, b=1, *args):
    print(a)
    return b

# Create jscode object
jscode = js(foo)

# Print some info that we have on the code
print(jscode.name)
print(jscode.pycode)
print(jscode.jscode)

# Convert strings of Python to JS
print(py2js('isinstance(x, str)'))
print(py2js('isinstance(x, Bar)'))

# Evaluate js in nodejs
print(evaljs('10 * 10'))

# Evaluate PyScript in nodejs
print(evalpy('10**10'))