String comparison

Greg Krohn ("X", "@") "gkrohnXvolucris.8m.com".replace
Wed Aug 21 14:11:20 EDT 2002


"David Iungerich" <david.iungerich at kwe.com> wrote in message
news:mailman.1029948751.3285.python-list at python.org...
> 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?

Are you POSITVE the strings are EXACTLY equal? I would add:

print len(str(postReply)), str(postReply)
print len(str(controlData)), str(controlData)

somewhere in there, right before the if-block maybe.





More information about the Python-list mailing list