【python】报错:TypeError: write() argument must be str, not bytes

在用 pickle.dump() 保存二进制文件时,一直报错,程序如下:

with open(os.path.join(FLAGS.train_data_dir, 'files.log'), 'w') as f:
   pickle.dump([training_paths, testing_paths], f)

【python】报错:TypeError: write() argument must be str, not bytes_第1张图片

查而得知,因为存储方式默认是二进制方式,故采用二进制方式打开。改为如下程序:

with open(os.path.join(FLAGS.train_data_dir, 'files.log'), 'wb+') as f:
    pickle.dump([training_paths, testing_paths], f)

 

 

 

 

你可能感兴趣的:(Python函数)