0

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.

17
  • is there only a single line in each log file? Are you trying to compare lines by line numbers or one line to the whole file? Commented Jun 27, 2017 at 20:33
  • They are maybe invisible characters in your strings. try converting them into bytes and compare the results. Commented Jun 27, 2017 at 20:34
  • Nah multiple for each log and every other line in log2 is blank. I'll pastebin the code. pastebin.com/xP0pibEc Commented Jun 27, 2017 at 20:35
  • 2
    Try replacing print(" [#] "+str(row)+' '+str(date)) with this: print([ord(x) for x in row], [ord(x) for x in date]) - this will print actual ASCII codes for characters in both your strings. Commented Jun 27, 2017 at 20:48
  • 1
    Well, that settles it - date comes from a file that's just ASCII (48 stands for 0, 54 for 6 etc.), but row does not. It is likely UCS2/UTF-16 encoding, and you should declare that encoding while opening that file. Commented Jun 27, 2017 at 20:56

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.