Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'languages,': 0.04; 'c++,': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'jan': 0.12; '"hello': 0.16; '>in': 0.16; 'assignments': 0.16; 'constructs.': 0.16; 'expressions.': 0.16; 'message-id:@4ax.com': 0.16; 'really?': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'java,': 0.16; 'thu,': 0.19; 'print': 0.22; 'url:home': 0.24; 'header:X-Complaints-To:1': 0.27; 'grouping': 0.31; 'core': 0.34; "can't": 0.35; 'useful': 0.36; 'charset:us-ascii': 0.36; 'list.': 0.37; 'to:addr:python-list': 0.38; 'visual': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'most': 0.60; 'break': 0.61; 'effective': 0.61; 'john': 0.61; 'such': 0.63; '"most': 0.84; 'common,': 0.84; 'world!"': 0.84; 'received:108': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dennis Lee Bieber Subject: Re: Ifs and assignments Date: Thu, 02 Jan 2014 19:45:05 -0500 Organization: IISS Elusive Unicorn References: <52C59FF6.5000607@allsup.co> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: adsl-108-79-217-221.dsl.klmzmi.sbcglobal.net X-Newsreader: Forte Agent 6.00/32.1186 X-No-Archive: YES 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: 46 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1388709915 news.xs4all.nl 2906 [2001:888:2000:d::a6]:60318 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:63014 On Thu, 02 Jan 2014 17:20:54 +0000, John Allsup declaimed the following: >Hi, > >This is my debut on this list. > >In many languages, such as C, one can use assignments in conditionals >and expressions. The most common, and useful case turns up when you Really? You can't do it in FORTRAN, BASIC, COBOL, Pascal, Ada... C, C++, Java, C# are all based on the same core syntax. For all effective purposes, they are the same as grouping M$ Visual BASIC, GW-BASIC, Kemeny&Kurtz TrueBASIC as "most languages, such as BASIC"... >have if/else if/else if/else constructs. Consider the following >non-working pseudoPython. > >import re >r1 = re.compile("hello (\d)") >r2 = re.compile("world([!?])") > >w = "hello world!" > matcher = [ (r1, handleMatch1), (r2, handleMatch2) ] >if m = r1.search(w): > handleMatch1(m) >elif m = r2.search(w): > handleMatch2(m) >else: > print("No match") > for r, h in matcher: m = r.search(w) if m: h(m) break else: print ("no match") -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/