UPDATE: Most (if not all) of these bugs have been fixed since I started using Pyjamas. This is here mainly for reference.
Pyjamas has a very useful migration guide which summarizes the current issues/differences between JS and Python that the developers did not yet resolve. It’s a very useful read for anyone using Pyjamas, both with JS and Python background and a must-read for anyone wishing to make an app that works both in browser and in Pyjamas-Desktop. I did find a few issues, however, that weren’t yet documented. So I decided to post them here, including the work-arounds.
Importing radians function from math
For some reason, the following code will cause an ImportError in JS:
However, doing the same with
math.sqrt works fine
Either use the following:
from math import radians
from math import pi
Concatenating two strings using +
The following works fine in Python and Pyjamas-Desktop, but throws an exception (that Pyjamas catches, and gives “inform the webmaster” error):
Ironically, passing the same into a function as an argument works fine in both:
The following alternative works in both:
Alternatively, if you want a cleaner-looking concatenation:
return ''.join(args) b="jamas"
Different modulo implementation
When performing the modulo command, Python uses the sign of the divisor for the result. JS, however uses the sign of the dividend. The following code in Pyjamas-Desktop will set a to 0.6, while in JS/browser it will set it to -0.4:
So far, my solution is to do the following:
a=dividend%divisor if a<0:
I also tried using
math.fmod() instead, but ran into the same ImportError issue as described above for radians, unfortunately using the work-around described above only works for
fmod() Pyjamas will throw “$module.math.fmod is not a function” exception