Python_文件内容去重

def remove_duplicates(file_path):
    lines = []
    with open(file_path, 'r',encoding='utf-8') as file:
        for line in file:
            line = line.strip()
            if line not in lines:
                lines.append(line)
    with open(file_path, 'w',encoding='utf-8') as file:
        for line in lines:
            file.write(line + '\n')

if __name__ == '__main__':
    file_path = 'C:\\Users\\xxx\\Desktop\\records.txt'
    remove_duplicates(file_path)