def write_txt(in_file, head, bodys, keylens=8):
    '\n    description: wangpeng add 20180615 (写入或更新txt)\n    :in_file 写入文件位置\n    :head  文件头信息\n    :bodys 文件体\n    :keylens 更新文件使用的第一列关键字长度\n    '
    allLines = []
    DICT_D = {}
    FilePath = os.path.dirname(in_file)
    if (not os.path.exists(FilePath)):
        os.makedirs(FilePath)
    if (os.path.isfile(in_file) and (os.path.getsize(in_file) != 0)):
        fp = open(in_file, 'r')
        fp.readline()
        Lines = fp.readlines()
        fp.close()
        for Line in Lines:
            DICT_D[Line[:keylens]] = Line[keylens:]
        for Line in bodys:
            DICT_D[Line[:keylens]] = Line[keylens:]
        newLines = sorted(iter(DICT_D.items()), key=(lambda d: d[0]), reverse=False)
        for i in range(len(newLines)):
            allLines.append((str(newLines[i][0]) + str(newLines[i][1])))
        fp = open(in_file, 'w')
        fp.write(head)
        fp.writelines(allLines)
        fp.close()
    else:
        fp = open(in_file, 'w')
        fp.write(head)
        fp.writelines(bodys)
        fp.close()
description: wangpeng add 20180615 (写入或更新txt)
:in_file 写入文件位置
:head  文件头信息
:bodys 文件体
:keylens 更新文件使用的第一列关键字长度
def write_txt(in_file, head, bodys, keylens=8):
    '\n    description: wangpeng add 20180615 (写入或更新txt)\n    :in_file 写入文件位置\n    :head  文件头信息\n    :bodys 文件体\n    :keylens 更新文件使用的第一列关键字长度\n    '
    allLines = []
    DICT_D = {}
    FilePath = os.path.dirname(in_file)
    if (not os.path.exists(FilePath)):
        os.makedirs(FilePath)
    if (os.path.isfile(in_file) and (os.path.getsize(in_file) != 0)):
        fp = open(in_file, 'r')
        fp.readline()
        Lines = fp.readlines()
        fp.close()
        for Line in Lines:
            DICT_D[Line[:keylens]] = Line[keylens:]
        for Line in bodys:
            DICT_D[Line[:keylens]] = Line[keylens:]
        newLines = sorted(iter(DICT_D.items()), key=(lambda d: d[0]), reverse=False)
        for i in range(len(newLines)):
            allLines.append((str(newLines[i][0]) + str(newLines[i][1])))
        fp = open(in_file, 'w')
        fp.write(head)
        fp.writelines(allLines)
        fp.close()
    else:
        fp = open(in_file, 'w')
        fp.write(head)
        fp.writelines(bodys)
        fp.close()