Path: csiph.com!usenet.pasdenom.info!news.albasani.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!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.021 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; '"("': 0.09; 'append': 0.09; 'integers': 0.09; 'iterate': 0.09; 'literal': 0.09; 'subject:How': 0.10; 'cc:addr:python-list': 0.11; 'python': 0.11; '")"': 0.16; '-tkc': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'readable': 0.16; 'roy': 0.16; 'two.': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'machine': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'header:In-Reply- To:1': 0.27; 'characters': 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'fri,': 0.33; 'comment': 0.34; 'subject:the': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'two': 0.37; 'list': 0.37; 'pm,': 0.38; 'little': 0.38; 'skip:u 10': 0.60; 'expression': 0.60; 'first': 0.61; 'skip:n 10': 0.64; 'more': 0.64; 'between': 0.67; 'close': 0.67; 'smith': 0.68; 'jul': 0.74; 'power': 0.76; 'commenting': 0.84; 'capture': 0.91; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=rHghkEyxHGabtp6HdzOdTgLUkiNRrrCfdWAVPDR5GwQ=; b=C4kRmE3octE1VoRXH8hcW4byqWdXuJ+cbo4I0kp0/wbD5gdayDJ9GTXPWFJkPJDV0N qzOOiy2paRnX3hGfwWPA3xQz7AbboX7MSnt6JcMya+EQO7Z256ZcbQ61GIYNfzgrHhXa xQ0+Jq1fpBqevUSYpo0gYFkPaLKuZ2nBi4fTulwJNqae1o8IHRjxAfYkTpqP2kKclPMb euUd1hZHBVRj5sip/3uolqfm+6zxUcf247esqnAmjIIYA6vDVI9UAEkUl2V90ahpJ7Po V8xNfS1c4CY/tXwia6qm4/H7SQzu3/a7YG1ZkW6ElhMo0BGb1rwfTnnkgqfeyg/326io cs3Q== MIME-Version: 1.0 X-Received: by 10.52.249.9 with SMTP id yq9mr29207964vdc.6.1405053085238; Thu, 10 Jul 2014 21:31:25 -0700 (PDT) In-Reply-To: References: <981c1f5f-2c19-4efc-8397-796bde07f39b@googlegroups.com> Date: Fri, 11 Jul 2014 14:31:25 +1000 Subject: Re: How to decipher :re.split(r"(\(\([^)]+\)\))" in the example From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 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: , Newsgroups: comp.lang.python Message-ID: Lines: 26 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1405053093 news.xs4all.nl 2878 [2001:888:2000:d::a6]:57807 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:74341 On Fri, Jul 11, 2014 at 1:33 PM, Roy Smith wrote: >> Or heck, use a multi-line verbose expression and comment it for >> clarity: >> >> r = re.compile(r""" >> ( # begin a capture group >> \({2} # two literal "(" characters >> [^)]+ # one or more non-close-paren characters >> \){2} # two literal ")" characters >> ) # close the capture group >> """, re.VERBOSE) >> >> -tkc > > Ugh. That reminds me of the classic commenting anti-pattern: > > l = [] # create an empty list > for i in range(10): # iterate over the first 10 integers > l.append(i) # append each one to the list Small difference between the two. Python is designed to be a readable language... regexps combine all the power and unreadability of machine code with the portability of machine code. ChrisA exaggerating... but only a little