Using assingment as an operator.

Terry Reedy tjreedy at home.com
Fri Oct 12 10:35:28 EDT 2001


"Emil S. Hansen" <esh at berlingske.dk> wrote in message
news:pan.2001.10.12.15.07.42.880.11244 at berlingske.dk...
> Hello fellow PP.
>
> I have a simple question. In a program I have a statement like this:
> while re.search("[^a-z0-9.]", domainname = raw_input("Please enter
domainname: ")) != None:
>         print "Error in domainname, please use lovercase letters and
numbers only."

Assuming re and test are correct (not sure are), rewrite as something
like

while 1:
  domainname = raw_input("Please enter domainname: "
  if re.search("[^a-z0-9.]", domainname ) == None: break # correct
test?
  print "Error in domainname, please use lowercase letters and numbers
only."
  # corrected 'lover' to 'lower'

While I once would have written this as you did (in C), I think there
is some virture to having the test condensed to where it can be seen
'all at once' without the assignment interpolated within.

Terry J. Reedy






More information about the Python-list mailing list