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()
'Technology > Programming' 카테고리의 다른 글
Python / 대용량 파일 빠르게 읽는 법 (0) | 2015.08.04 |
---|---|
[jQuery] jQuery Select Box 제어하기 (1) | 2014.05.16 |
Python / 숫자, 소수점 정규표현식 (0) | 2012.07.23 |
Python / Text parsing and match (0) | 2012.05.11 |
Python / CSV파일에서 그룹지어 계산하기 (0) | 2012.05.11 |