Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'syntax': 0.03; 'subject:Python': 0.05; 'cpython': 0.05; 'reject': 0.05; 'nested': 0.07; 'python': 0.09; '"+"': 0.09; 'methods,': 0.09; 'module)': 0.09; 'structure,': 0.09; 'to:addr:comp.lang.python': 0.09; 'url:github': 0.09; 'will,': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; ';-)': 0.11; "skip:' 30": 0.15; "'hello": 0.16; '(just': 0.16; 'chained': 0.16; 'cleaner': 0.16; 'framework,': 0.16; 'means:': 0.16; 'pythonic': 0.16; 'recipe': 0.16; 'syntax,': 0.16; 'string': 0.17; '>>>': 0.18; 'code.': 0.20; 'proposed': 0.20; 'fairly': 0.21; 'supposed': 0.21; 'skip:% 10': 0.22; 'skip:_ 20': 0.22; 'cc:2**0': 0.23; 'this:': 0.23; "i've": 0.23; 'thus': 0.24; 'cc:no real name:2**0': 0.24; 'idea': 0.24; 'least': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'tree': 0.27; 'options': 0.27; 'dom': 0.29; 'proposing': 0.29; 'no,': 0.29; 'class': 0.29; 'code': 0.31; 'structure': 0.32; 'could': 0.32; 'programming,': 0.33; 'problem': 0.33; 'skip:d 20': 0.34; 'received:google.com': 0.34; 'self': 0.34; 'done': 0.34; 'problem,': 0.35; 'returning': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'explain': 0.36; 'skip:u 20': 0.36; 'but': 0.36; 'method': 0.36; 'should': 0.36; 'bad': 0.37; 'does': 0.37; 'level': 0.37; 'quite': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'fact': 0.38; 'easily': 0.39; 'real': 0.61; 'first': 0.61; 'different': 0.63; 'world': 0.63; 'hang': 0.65; 'sum': 0.66; 'obvious': 0.71; 'self.value': 0.84; 'ugly,': 0.84; 'url:master': 0.84; 'faced': 0.91 Newsgroups: comp.lang.python Date: Fri, 21 Dec 2012 07:36:43 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=193.49.124.107; posting-account=cEyVOAoAAAAQ26Zg5AgQClqyybEKp-yz References: <50D256B3.4070709@udel.edu> <96edb672-dabd-4ab8-9e7c-3fa7f4a91437@googlegroups.com> User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 193.49.124.107 MIME-Version: 1.0 Subject: Re: Brython - Python in the browser From: Pierre Quentel To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: Lines: 58 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1356104211 news.xs4all.nl 6950 [2001:888:2000:d::a6]:56408 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:35298 > Pythonic also means: > If the implementation is hard to explain, it's a bad idea. > What, exactly, does the sum of a string and a bolded string produce? Can= you explain that easily and clearly? Yes : a+b returns the string a+str(b) It is exactly what you get in CPython with=20 >>> class B: ... def __init__(self,value): ... self.value =3D value ... def __radd__(self,other): ... return '%s%s' %(other,self.value) ... >>> 'hello '+B('world') 'hello world' > The DOM structure is, undeniably, quite verbose. But you could go for > something with the same tree structure while a lot less wordy by > simply returning self from lots of methods, thus allowing method > chaining - something like this: >=20 > https://github.com/Rosuav/Gypsum/blob/master/window.pike#L247 >=20 Hang me if I understand what this code is supposed to do ;-) >=20 > To produce the HTML code >=20 >
hello world
>=20 > you might use: >=20 > doc.add(Tag('DIV').add('hello ').add(Tag('B').add('world'))) >=20 No, with this syntax, the result of Tag('B').add('world') is below 'hello' = in the tree structure, not at the same level (just below Tag('DIV')) as it = should be In this case it's not a real problem, but it's obvious if you want to produ= ce
  • one
  • two
: you would need 2 different 'add' top =3D Tag('UL') top.add(Tag('LI').add('one')) top.add(Tag('LI').add('two')) With the syntax used in Brython : UL(LI('one')+LI('two')) >=20 > Reject the idea if you will, but do at least please consider it :) >=20 I did in fact consider many options before proposing this one. I have done = a lot of web programming, including a web framework, and I faced the proble= m of generating HTML code from Python. I started with a syntax with nested = parenthesis and chained methods returning self, only ending in ugly, unread= able code. Once I started using <=3D for "add child" and "+" for "add broth= er" (I first proposed it in the Python Cookbook recipe #366000, the HTMLTag= s module) - and I've used it on fairly large projects - the result was a mu= ch cleaner code