Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #63014

Re: Ifs and assignments

From Dennis Lee Bieber <wlfraed@ix.netcom.com>
Subject Re: Ifs and assignments
Date 2014-01-02 19:45 -0500
Organization IISS Elusive Unicorn
References <52C59FF6.5000607@allsup.co>
Newsgroups comp.lang.python
Message-ID <mailman.4816.1388709915.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Thu, 02 Jan 2014 17:20:54 +0000, John Allsup <pydev@allsup.co> 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/

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: Ifs and assignments Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-01-02 19:45 -0500
  Re: Ifs and assignments Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-01-03 14:33 +1100
    Re: Ifs and assignments Chris Angelico <rosuav@gmail.com> - 2014-01-03 14:49 +1100
      Re: Ifs and assignments Roy Smith <roy@panix.com> - 2014-01-02 23:14 -0500
        Re: Ifs and assignments Chris Angelico <rosuav@gmail.com> - 2014-01-03 15:25 +1100
        Re: Ifs and assignments Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-01-03 04:29 +0000
      Re: Ifs and assignments Duncan Booth <duncan.booth@invalid.invalid> - 2014-01-03 15:46 +0000
    Re: Ifs and assignments Chris Angelico <rosuav@gmail.com> - 2014-01-03 14:55 +1100
      Re: Ifs and assignments Roy Smith <roy@panix.com> - 2014-01-02 23:00 -0500
        Re: Ifs and assignments Chris Angelico <rosuav@gmail.com> - 2014-01-03 15:08 +1100

csiph-web