Alloy
Alloy

Reputation: 418

Python string comparison not evaluating as expected

I have a date in one file and one in another. They look like this:

log1.log -> "06/11/2017"

and

log2.log -> "06/11/2017"

Specifically looking for matches like this, I've written this bit:

if row != date:
  pass
elif row == date:
  print("match found")

And I have already tried making the logic, rather than check for inequality, check for equality; but it didn't work. I've also exported the values found into a new text file and checked for whitespace or newlines which would be hard to detect in a terminal. No dice.

Printing the dates to the terminal confirms that they are indeed matches.

Example output:

[#] 06/13/2017 06/13/2017

When I print them both with a space in between them and that hash notation to keep the printout looking organized.

Last thing I tried is superficially converting both of them to strings in the comparison. Am I nuts? What's going on here?

I can provide anything but the data itself. However we're talking literally just .log files with lines I've used split to grab and so I offer the output above to rule out any data issues.

edit: when you edited my post, you absolutely murdered my grammar and readability dude. it was gibberish as far as the English language is concerned when you were done with it. Let's leave it alone for now, k? The subject of the sentence is "the logic". What I've edited back is just fine. And you do not need to disclaim pluralization on "whitespace". It's already implied there could be multiple instances of it.

Upvotes: 0

Views: 94

Answers (1)

Błotosmętek
Błotosmętek

Reputation: 12927

Use encoding='UTF-16LE' argument when opening the file.

Upvotes: 1

Related Questions