Brython - Python in the browser
tjreedy at udel.edu
Fri Dec 21 00:59:39 CET 2012
> On Thu, Dec 20, 2012 at 8:37 PM, Pierre Quentel
> <pierre.quentel at gmail.com> wrote:
>> I'm afraid I am going to disagree. The document is a tree
>> structure, and today Python doesn't have a syntax for easily
>> manipulating trees.
What Python does have is 11 versions of the augmented assignment
statement: +=, -=, *=, /=, //=, %=, **=, >>=, <<=, &=, ^=, |=.
Moreover, these are *intended* to be implemented in place, by mutation,
for mutable objects, with possibly class-specific meanings.
>> To add a child to a node, using an operator
>> instead of a function call saves a lot of typing ;
We agree. Just use the proper sort of operator. I believe you said
elsewhere that you *are* using one augmented assignment, +=, to add a
sibling. That is a proper use. I am saying to use another to add a child.
<= 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.
>> <= looks like a
>> left arrow, which is a visual indication of the meaning "receive as
>> child". |= doesn't have this arrow shape
If you want to talk shape, I could argue that you should use -= for
adding a sibling (horizontal link, -) and |= for adding a child
(vertical link, |). Since you probably want to stick with += and like
the 'arrowness' of <=, use the augmented assignment operator <<= instead
of comparison operator <=.
Terry Jan Reedy
More information about the Python-list