
Pythonium: Python 3 to JavaScript translator - ma2rten
https://pypi.python.org/pypi/pythonium/0.4.5
======
rdtsc
Also

Pyjamas: [http://pyjs.org/](http://pyjs.org/)

Skulpt: [http://www.skulpt.org/](http://www.skulpt.org/)

and another one I forgot.

They are all are cool projects. They diligently solve 73.56% of the problem of
Python to Javascript translation, and the other 26.44% remains a very hard
task. This is not unlike many other problems in programming (well, even in
real life). So it is not for the lack of knowledge, experience or hard work,
it is just a very hard problem.

~~~
paulftw
Another one is [http://brython.info/](http://brython.info/)

~~~
rdtsc
Yes, that's the one. Thank you.

------
wting
There's also a quick demo of Pythonium here:

[http://pythonium.github.io/](http://pythonium.github.io/)

The generated JS:

[http://pythonium.github.io/js/app.py.js](http://pythonium.github.io/js/app.py.js)

~~~
e12e
But the python source isn't available? The project seems rather light on
example code for now...

~~~
ma2rten
I found it:

[https://github.com/pythonium/pythonium.github.io/blob/master...](https://github.com/pythonium/pythonium.github.io/blob/master/js/app.py)

------
vonseel
How would one go about writing an HTTP call in Python and converting to
appropriate XMLHttpRequest in JavaScript? Is this project capable of something
like that, and using the native JavaScript ability, rather than a predefined
jQuery variable?

Trying to understand what this would be used for besides basic object mapping,
iterating, etc.

~~~
shantanubala
XMLHttpRequest is a facility provided by the browser - when you are making a
request, you are just accessing objects and functions provided by the host
environment.

In Python, the "host environment" is generally CPython with the standard
library. In JavaScript, the "host environment" is typically the browser with
the DOM.

This is a project that translates code in Python syntax to JavaScript, so you
would use XMLHttpRequest just as you would in JavaScript, but with Python
syntax.

~~~
knappador
So if I get the names perfect, I can use the js API's provided by the browser
and only need to compile to test my code? Next. No...not next. Please no more
next. Make it stop. Just stop. Please. There are so many projects that can use
your assistance. I can give you ten open issues off the top of my head that I
would like fixed. So many useful, interesting, thought-provoking programs are
just dying to be written.

~~~
bulatb
If they haven't already, they could hide the DOM and nasty host-provided
objects behind something more Pythonic. As long as it transpiles to
XMLHttpRequests, it doesn't matter what the Python looks like.

~~~
knappador
And I'll build a mock environment so that I can run my python script as if
there is a real DOM to manipulate, and then I'll write a test rendering system
to actually display the page as if everything is running in Python. Eventually
I'll just implement every single aspect of a web browser so that I can be sure
that after I stop transpilfering Python, I can indeed just start putting
<script type="text/python"> everywhere and convince everyone to use it, so my
giant mock environment will become the latest, greatest browser, and Google
will spend millions adding a tune-able JIT to cpython, leading someone to
decide what a great idea it would be to use this JIT as the runtime for
server-side Python, and Pode.py will take over the web, and "isomorphic"
Python frameworks will sprout faster than TCP connections on a DDOS'd server.

And after that, we can start writing and re-writing everything to "transpile"
to PHP and use hip-hop to make it C++. I can't spend any more attention on
random me-to JS without feeling like I'm waiting for my vestigial appendix to
fall out.

------
cookiecaper
I'd prefer a real solution to the JavaScript problem: put a real language in a
web browser. JavaScript has done very well for what it is, but even Brendan
Eich openly admits it was a rushed project and was never intended to be the
One True Client-Side Programming Stack.

We have lots of people writing very complex programs meant to alleviate some
of the problems with JavaScript, when that effort could reasonably go into
making Python a first-class web language by including a VM in browser
distributions and writing bindings that allow DOM manipulation.

~~~
icebraining
We have a VM in browser distributions, it's called JavaScript.

~~~
MrBra
And no one is complaining about it.

------
leoh
These kinds of things are cute and fun—but does anyone use these sorts of
language x to language y translators in practice? Not talking about
specialized language interpretation. With JavaScript, the most common
operation is to manipulate and capture from the DOM—something that this tool
is not capable of readily doing, not, at least, without getting one's hands
dirty with JS.

~~~
terhechte
I think ClojureScript is actively being used in practice. I think most others
are more or less neat experiments.

~~~
chubot
Pretty sure Light Table is built in ClojureScript (on top of Node-Webkit),
which is pretty impressive!

------
solox3
I wonder how multiple inheritance is handled by this webdev holy grail. I know
CoffeeScript had some issues handling its certain attributes* within its
constructors, so it'll be interesting to see how pythonium does the same and
beyond.

* forgot what

~~~
jashkenas

        > I know CoffeeScript had some issues handling its certain attributes* 
        > within its constructors
    

Oh really? Do tell.

~~~
solox3

        class a
          constructor: ->
            # conventionally logs 3
            console.log @c
    
        class b extends a
          c = 3
    
        new b()  # logs undefined

~~~
jashkenas
Not quite. Key-value _properties_ use the colon syntax. Regular assignment is
for local variables. Your "c" is a local variable within the class body of
"b", and should absolutely not be visible from the constructor of "a".

Here's the corrected version:

    
    
        class a
          constructor: ->
            console.log @c
    
        class b extends a
          c: 3
    
        new b()  # logs 3

~~~
solox3
Today the whole office learned. Thanks a bunch, Jeremy!

------
mmgutz
Is there an online transpiler to compare the Python source to the generated
JavaScript as on the CoffeeScript site?

~~~
amirouche
You can compare the Javascript code generated by the Veloce mode [0] and by
compliant mode [1]

[0]
[https://gist.github.com/amirouche/7768738](https://gist.github.com/amirouche/7768738)
[1]
[https://gist.github.com/amirouche/7768858](https://gist.github.com/amirouche/7768858)

------
ilaksh
If you like Python you should really look at CoffeeScript and even better
ToffeeScript. You can write code that looks a lot like Python. Actually the
spirit of Python is to be close to pseudo code, and if you want to you can
write CoffeeScript/ToffeeScript that beats Python in that respect.

~~~
kayoone
oh so ToffeeScript is the latest fashion now ? See, thats why i dont get into
any of those alternative JS syntaxes.

~~~
chc
If you refrain from any area where one thing might be more popular than
another, you're going to have a very hard time getting anything done.

~~~
porker
I do find the number of options hard to choose from. The hacker approach seems
to be to learn a bit of everything (and enjoy it) but for people like me where
programming is a necessary tool to get shit done, trying to decide between
these 10 options and pick one that will turn out to be the best/still be
useful in 3 years is hard.

------
analog31
This should help me learn JavaScript!

~~~
ma2rten
I don't think that is good idea. Javascript has it's own idioms and also
gotchas. You are not going to learn them by looking at translated python code.
Read JavaScript The Good Parts instead.

~~~
acjohnson55
And Javascript Allongé, my personal favorite!

[https://leanpub.com/javascript-allonge/read](https://leanpub.com/javascript-
allonge/read)

------
daemonk
Anonymous functions?

