import MySQLdb
import datetime
import time
fopen = open("sample.txt", "r")
fresult = open("data3_drug_era.txt", "w")
def split_date(_date):
arrDate = _date.split("-")
return datetime.date(int(arrDate[0]), int(arrDate[1]), int(arrDate[2]))
try:
group = []
for i, each_line in enumerate(fopen):
(pk, concept, person, visit, a, value, start, end, interval, unit, quantity, import_date) = each_line.split("\t")
import_date = import_date.strip()
day_start = split_date(start)
day_end = split_date(end)
day_interval = day_start + datetime.timedelta(weeks=1)
print i, pk, day_start, day_interval
except IOError:
print "Error"
fresult.close()
fopen.close()