You're iterating over csvReader
, which yields you the header row, too.
# First row
['Date', 'Name', 'City']
# Second row
['2020-12-27 18:11:16', 'John', 'New York']
# Third row
['2020-12-29 17:44:23', 'Mary', 'Berlin']
String 'Date'
doesn't equal to string '2020-12-27 18:11:16'
, so the print("Ok")
branch of your IF is executed.
As to why 6 "Ok" messages
are being printed - I guess you're doing all that multiple times - because of the number stored in variable amountMessages
.
for number in range(amountMessages):
...
Bonus LPT (Life Pro Tip) ??
If unsure, often the easiest thing to do is to put interactive debugger in there - and you can inspect variables at that point during execution.
If you have Python <3.7
, you can simply put import pdb; pdb.set_trace()
inside your code, like this:
...
for row in csvReader:
import pdb; pdb.set_trace()
if row[0] == date
...
...
... and run your code. This way you will get interactive debugging session at that point, where you can do things like...
(Pdb) yay = 123
(Pdb) yay
123
(Pdb) row[0]
'Date'
If you have Python >=3.7
, the built-in breakpoint()
function is available, which you can use instead.
More info about pdb
at Python official docs: https://docs.python.org/3/library/pdb.html
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…