String comparison

David Iungerich david.iungerich at kwe.com
Thu Aug 22 17:00:02 CEST 2002


There was some whitespace junk in the file.  The following works fine.

	try:
		postReply = urllib.urlopen("http://css.kwe.com/web.forte",
postdata).read()

		f = open("D:\PythonServerMonitor\KWE1144589.dat","r")
		controlData = f.read()
		f.close()

		print "     <ControlData>" + str(len(controlData)) + "</ControlData>"
		print "     <ServerData>" + str(len(postReply)) + "</ServerData>"

		if (postReply == controlData):
			response = "<ServerResponseTest>Response - OK</ServerResponseTest>"
		else:
			response = "<Result>Server Not Responding</Result>"
   		# e-mail appropriate party.

	except Exception:
		print Exception
		f.close
		# e-mail the admin.

-----Original Message-----
From: python-list-admin at python.org
[mailto:python-list-admin at python.org]On Behalf Of Brian Jones
Sent: Thursday, August 22, 2002 3:57 AM
To: python-list at python.org
Subject: Re: String comparison


> if s1.lower() == s2.lower():
>    blah()
>
> I suppose this would do the trick, too:
>
> if re.match( '^' + s1 + '$', s2, re.I ):
>    blah()
>
> I'm not sure which of these is better (or maybe it is neither!), though,
so,
> of course, I'd like to know what the One True Path is...

As a real Python newbie making his first post here may I vote for the
former.

For me one of Python's great strengths is that it does not carry the
baggage of C++ or Java, and avoids the obfuscation of Perl (and readily
available in C). It is clean and intrinsically simple.

The first of your choices bears the simplicity of Python whilst the
second reminds me of Perl.

Regexs are powerful when they are needed but why add complexity and
decrease readability where they are not needed.

Brian
--
http://mail.python.org/mailman/listinfo/python-list





More information about the Python-list mailing list