pythonian comparison: date.time from csv file to date.time from timestamp
Question: In python I import a csv file with one datetime value at each row (2013-03-14
07:37:33) and I want to compare it with the datetime values I obtain with
timestamp. I assume that when I read the csv the result is strings, but when I
try to compare them in a loop with the strings from timestamp does not compare
them at all without giving me an error at the same time.

Any suggestions?

    
    
    csv_in = open('FakeOBData.csv', 'rb')
    reader = csv.reader(csv_in)
    
    for row in reader:
        date = row
        OBD.append(date)
    

. . .

    
    
    for x in OBD:
        print x
        sightings = db.edge.find ( { "tag" : int(participant_tag)},{"_id":0}).sort("time")
        for sighting in sightings:
            time2 = datetime.datetime.fromtimestamp(time)
            if x == time2:
    


Answer: Use
[datetime.datetime.strptime](http://docs.python.org/2/library/datetime.html#datetime.datetime.strptime)
to parse the strings into datetime objects. You may also have to work out what
time zone the date strings in your CSV are from and adjust for that.

`%Y-%m-%d %H:%M:%S` should work as your format string:

    
    
    x_datetime = datetime.datetime.strptime(x, '%Y-%m-%d %H:%M:%S')
    if x_datetime == time2:
    

Or parse it when reading:

    
    
    for row in reader:
        date = datetime.datetime.strptime(row[0], '%Y-%m-%d %H:%M:%S')
    

