Brython-specific built-in modules
Working with Brython
Brython for Firefox OS
Frequently asked questions
Q : what does "Brython" mean ?
A : Browser Python. It's also the Welsh word for "breton".
Q : which browsers support Brython ?
Note that performance is usually better (sometimes much better) with Firefox than with Chrome.
The diffence is due to two factors :
The Brython repository includes a script, at address localhost:8000/speed, that
compares the speed of Bython and CPython on the local machine for a variety of
Q : I see a lot of 404 errors in the browser console when I run Brython scripts, why is that ?
ImportError if all paths have been tried with no result
Q : why does this message show in the browser console : "Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help http://xhr.spec.whatwg.org/" ?
A : this is also related to imports, or to file reading. To achieve these operations, Brython uses blocking Ajax calls : an imported module must be loaded before it can be used. Browser vendors should normally not remove blocking calls any time soon.
Q : is it possible to precompile Brython scripts, in order to reduce execution time ?
Another reason why it is a not a good idea to precompile Brython is that the generated code is typically 10 times bigger than the original Python source - this is the price to pay for compliance with the language specification. The page would take longer to load, and we haven't found that this would be faster than compiling on the fly.
Q : why use the operator
<= to build the tree of DOM elements ? This is not pythonic !
A : Python has no built-in structure to manipulate trees, ie to add "child" or "sibling" nodes to a tree node. For these operations, functions can be used ; the syntax proposed by Brython is to use operators : this is easier to type (no parenthesis) and more readable
To add a sibling node, the operator
+ is used
To add a child, the operator
<= was chosen for these reasons :
- it has the shape of a left arrow ; note that Python function annotations use a new operator
-> that was chosen for its arrow shape
- it looks like an augmented assignment because of the equal sign
- it can't be confused with "lesser or equal" because a line with
document <= elt would be a no-op if it was "lesser or equal", which is always used in a condition or as the return value of a function
- we are so used to interpret the 2 signs
= as "lesser or equal" that we forget that they are a convention for programming languages, to replace the real sign
- in Python,
<= is used as an operator for sets with a different meaning than "lesser or equal"
- the sign
< is often used in computer science to mean something else than "lesser than" : in Python and many other languages,
<< means left shift ; in HTML tags are enclosed with
- Python uses the same operator
% for very different operations : modulo and string formatting