Brython - Python in the browser

Ian Kelly ian.g.kelly at gmail.com
Wed Dec 19 19:54:44 EST 2012


On Wed, Dec 19, 2012 at 5:07 PM, Terry Reedy <tjreedy at udel.edu> wrote:
> That says that my browser, Firefox 17, does not support HTML5. Golly gee. I
> don't think any browser support5 all of that moving target, and Gecko
> apparently supports about as large a subset as most.
> https://en.wikipedia.org/wiki/Comparison_of_layout_engines_%28HTML5%29
> It is possible the FF still does not support the particular feature needed
> for the clock, but then the page should say just that. Has the latest FF
> (17) actually been tested?

It works for me using FF 17.0.1.

>> To create an element, for instance an HTML anchor :
>> doc <= A('Python',href="http://www.python.org")
>
>
> To me, that is a awful choice and I urge you to change it.

+1.  The DOM already has a well-established API.  The following may
require more typing:

link = document.createElement('a')
link.setAttribute("href", "http://www.python.org/")
link.appendChild(document.createTextNode('Python'))
document.body.appendChild(link)

But it is much clearer in intent.  Since these methods map directly to
DOM methods, I know exactly what I expect them to do, and I can look
them up in the browser documentation if I have any doubts.  With the
one-liner above, I don't know exactly what that maps to in actual DOM
calls, and so I'm a lot less clear on what exactly it is supposed to
do.  I'm not even entirely certain whether it's actually equivalent to
my code above.

I suggest that Brython should have a "low-level" DOM API that matches
up to the actual DOM in as close to a 1:1 correspondence as possible.
Then if you want to have a higher-level API that allows whiz-bang
one-liners like the above, build it as an abstraction on top of the
low-level API and include it as an optional library.  This has the
added benefit that if the user runs into an obscure bug where the
fancy API breaks on some particular operation on some specific
browser, they will still have the option of falling back to the
low-level API to work around it.  It would also make the conversion
barrier much lower for web programmers looking to switch to Brython,
if they can continue to use the constructs that they're already
familiar with but just write them in Python instead of JavaScript.



More information about the Python-list mailing list