使用Pickle将列表写入文件

时间:2018-09-25 16:04:09

标签: python file-io

我正在读取一组文件到列表,然后使用Pickle.dump将列表写到单个文件中。但是,某些无效字符会像\80]q\00(XK\00\00\00一样被添加到新文件的开头。如何删除这些?

if(gyro):
            lines = []
            for fil in gyro:
                file_name = os.path.join(file_path,fil)
                file_data = open(file_name)
                lines.extend(file_data.readlines())
                file_data.close
                os.remove(file_name)     
            uncompressed_filename = "raw_gyro.txt"
            uncompressed_filename = os.path.join(file_path,uncompressed_filename)
            with open(uncompressed_filename, "wb") as fp3:
                print("Created",uncompressed_filename)
                pickle.dump(lines, fp3)

0 个答案:

没有答案