Links
- Related
- Home
- Translator
- Migration Guide
- How suitable is pyjs as a standalone Python -> Javascript translator?
- This thread has a lot of helpful information on using just the JS translator portion.
- pyjsbuild is like
gcc
(a wrapper + "packager"), and pyjscompile is likecc
(raw translation). - pyjscompile is what you are looking for, but you will have to ensure all supporting libraries and the python runtime itself gets properly translated.
- you must use pyjscompile to translate your modules, all their dependencies, and and the stdlib manually.
- Aside from the translated modules, you'll need
pyjs/src/pyjs/builtin/public/_pyjs.js
- some of
pyjs/src/pyjs/builtin/public/bootstrap.js
- responsible for kickstarting the whole process, and actually starting the "python" runtime
- Browse source: github
- API
- Learning Resources
Gotchas
See also: dynamic.py depends on DOM.py why? trouble with pyv8run of simple script
Mostly from the migration Guide
- Supported modules
- base64, binascii, csv, datetime, math, md5, os, random, re, sets, struct, sys, time, urllib
- Supported types
- dict, frozenset, int, list, long, object, set, tuple
- Supported builtins
__import__
, abs, all, any, bool, callable, chr, cmp, delattr, dir, divmod, enumerate, filter, float, getattr, hasattr, hash, hex, isinstance, issubclass, iter, len, map, max, min, oct, open, ord, pow, property, range, reduce, repr, reversed, round, setattr, sorted, staticmethod, str, sum, super, type, xrange, zip
- Generators are supported.
- Multiple inheritance is also supported, as is the creation of metaclasses using three arguments to the builtin "type" function.
- Unicode is not supported.
- Tuple addition is currently not supported.
- Callables
- Javascript simply doesn't support callables
- The python
–strict
option can be applied to enable wrappers for every function call to support this. (This makes the javascript even slower). - So, without
–strict
, you can't implement call on your objects, and you can't pass an object where a function is expected. - Classes, however, are different. Even with
-O
, you can instantiate classes by passing the class object as a variable, and calling it.