#-*- coding:utf-8 -*-
import time
import datetime
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
def msg():
f = open('test.txt','r')
'''
李丽丽 320382199606160123
徐华彩 320382199606160134
蔺小虎 320382199606160145
葛俊 320382199606160156
'''
res = f.readlines()
for i in range(len(res)):
result = res[i].replace(' ', '').replace('\t', '').replace('\n', '').replace('\r', '')
name = result[0:-18]
num = result[-2:-1]
now_time = datetime.datetime.now()
time = datetime.datetime.now().strftime('%Y%m%d')
year = result[-12:-4]
age = int(time[0:4]) - int(year[0:4])
if int(time[4:]) > int(year[4:]):
age = age
else:
age = age - 1
if int(num) % 2 == 0:
sex = "女".decode('utf-8').encode('gbk')
else:
sex = "男".decode('utf-8').encode('gbk')
with open('oeder.txt', 'a') as f:
f.write(str(name) + ' ' + str(sex) + ' ' + str(age) + '\n')
f.close()
f.close
if __name__ == "__main__":
start = time.clock()
msg = msg()
end = time.clock()
print u'保存完成,共耗时:'+str(end - start)
追问十分感谢
本回答被提问者采纳