String comparison

Sean 'Shaleh' Perry shalehperry at attbi.com
Wed Aug 21 13:00:05 EDT 2002


>
>  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?

Some experimentation in the Python interpreter will help you.

>>> s = 'Sam'
>>> f = 'Frank'
>>> s == f # false
0
>>> s == s # true
1
>>> sam = 'Sam'
>>> s == sam # true
1

as you can see, string == string works.  Most likely your data is either not a 
proper string OR they are not perfect matches.  A space, newline, anything 
like that would change the answer.

Try running the pieces of your script in the interpreter by hand, should point 
out the error rather quickly.




More information about the Python-list mailing list