Brython - Python in the browser

Rouslan Korneychuk rouslank at msn.com
Fri Dec 21 09:31:42 CET 2012


On 12/20/2012 04:37 AM, Pierre Quentel wrote:
>>
>>> 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.
>>
>> '<=' is not just an operator, it is a comparison operator. It normally
>> return False or True. Numpy array comparison returns arrays of booleans,
>> so the meaning is extended, not completely changed. People will often be
>> using it with its normal mean in conditionals elsewhere, so this usage
>> creates strong cognitive dissonance. Also, using an expression as a
>> statement is allowed, but except in the interactive interpreter, it only
>> makes sense with an expression that obviously has side-effects or could
>> have side-effects (like the expression 'mylist.sort()'. It just looks
>> wrong to an experienced Python programmer like me.
>>
>> It also is unnecessary. Use '+=' or '|='. The former means just what you
>> want the statement to do and the latter is at least somewhat related
>> (bit or-addition) and is rarely used and is very unlikely to be used in
>> code intended for a browser.
>>
> 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. To add a child to a node, using an operator instead of a function call saves a lot of typing ; <= looks like a left arrow, which is a visual indication of the meaning "receive as child". |= doesn't have this arrow shape
>
> += is supported by Brython, but it means something different. <= means "add child" ; the addition operator + means "add brother"

Although I'm not really in favor of using an operator for this sort of 
thing either way, I can't help but notice the discussion seems to be 
limited to Python's operators. If you're implementing Python yourself, 
can't you define a new operator that is unambiguous?



More information about the Python-list mailing list