Brython - Python in the browser

Ian Kelly ian.g.kelly at gmail.com
Fri Dec 21 19:31:11 CET 2012


On Fri, Dec 21, 2012 at 9:16 AM, Pierre Quentel
<pierre.quentel at gmail.com> wrote:
>> <= is a comparison expression operator, which is completely different.
>> It is just wrong for this usage. I am 99.9% sure you will come to regret
>> it eventually. Better to make the change now than in Brython2 or Brython3.
>
> I am 99.99% sure of the contrary, having used this syntax for more than 3 years now, as the users of the Karrigell framework with the HTMLTags module
>
> Another point why there is no possible confusion is that when <= is a comparison operator, it is never used in an standalone expression like "a <= b", with the left term of the comparison starting the line ; it is always used in an expression like "if x <= 10", "while x <= 5", "assert x <= 0", "return foo <= bar" etc.
>
> So when you see a line like
>
> doc <= DIV('hello')
>
> it should be obvious that you are not *comparing* doc and DIV('hello'), because if it was the case, the line would do nothing

The interpreter, though, will be more than happy to treat that as a
comparison if the LHS is not the type that you think it is.  For
example, maybe you've added it to a string at some point, and now it's
a string instead of an element.  I guess that since doc is made a
keyword, that probably couldn't happen in this example, but it could
happen when trying to add child nodes to other nodes.

By the way, what is Brython actually doing when you append a child to
the document itself like that?  Usually I would expect a div to be
appended to the body or to another div.  The above looks like it would
attach the new div as a sibling of the html element.  Or is it just
calling document.write()?



More information about the Python-list mailing list