How can I use Brython to pile Python to Javascript? I want to do this on my puter, so I can the run Javascript with nodejs, eg.
$ python hello.py
Hello world
$ brython hello.py -o hello.js
$ node hello.js
Hello world
The examples on the Brython website only explain how do this in the browser .html
How can I use Brython to pile Python to Javascript? I want to do this on my puter, so I can the run Javascript with nodejs, eg.
$ python hello.py
Hello world
$ brython hello.py -o hello.js
$ node hello.js
Hello world
The examples on the Brython website only explain how do this in the browser http://www.brython.info/index_en.html
Share Improve this question edited May 17, 2021 at 14:01 Colonel Panic asked Feb 20, 2013 at 13:29 Colonel PanicColonel Panic 138k97 gold badges417 silver badges479 bronze badges3 Answers
Reset to default 9It seems they are very browser oriented, there is no mand line option out of the box.
You can try to use their code youself from node.js, perhaps it will work easily. It seems the $py2js(src, module)
function does the actual conversion so maybe you can just run it with the python code string as first parameter.
Another option is to use pyjs: http://pyjs/ which does something similar and has mand line tool to do the conversion.
It is possible to pile Python code to javascript and load it afterwards using import statement . See brython:ticket:222 for further details. You'll have to load brython js lib in advance because , in the end, Python semantics are quite different from Javascript's . You can include piled .pyc.js code in .vfs.js files in order to speed up module import times.
Disclaimer : I'm a mitter of Brython project .
Brython has a console that runs in the browser, but not a piler. It is meant for you to either import your python scripts into the html file, or write your python code into the html file. See pyjs if you wish a conversion tool before the page loads.