In [1]:
from flexx.pyscript import py2js, evalpy

In [2]:
js = py2js('for i in range(10): print(i)')
print(js)


var i;
for (i = 0; i < 10; i += 1) {
    console.log(i);
}

In [3]:
def foo(x):
    for i in range(x):
        print(i**2)
js = py2js(foo)
print(js)


var foo;
foo = function (x) {
    var i;
    for (i = 0; i < x; i += 1) {
        console.log(Math.pow(i, 2));
    }
    return null;
};


In [4]:
class Bar:
    def spam(self):
        return 3 + 4
#js = py2js(Bar)
# This only works if Bar is defined in an actual module.

Using evalpy you can evaluate Python code in NodeJS


In [5]:
evalpy('3*"3"')


Out[5]:
'9'

In [ ]: