String comparison

David Iungerich david.iungerich at kwe.com
Wed Aug 21 12:51:46 EDT 2002


I'm new to Python.  I'm most comfortable with Java, but have done work in
several other languages.  So far Python has proven rather annoying to deal
with.  I'm trying to do a simple string comparison, but have had problems
thus far.  Essentially, I have code that does an http POST.  I want to
compare the response string with a copy of it that is in a file (previous
request).  This is essentially a test to see if a server is up and
retrieving data correctly.  If not, I'll be sending an e-mail to an admin.
The actual string comparison is eluding me, though.  I've tried the
following.  Any help would be appreciated.

Obviously, this code is not complete.  I'll be replacing several values with
attibutes pulled from an XML file.  I'm just hardcoding things to test the
process right now.

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

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

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

 return response

I've also tried...
 if (strcmp(postReply, controlData) == 0):

In Java, I would simply use the .equals( ) method available to string
objects.

Thoughts?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20020821/4918469e/attachment.html>


More information about the Python-list mailing list