Python——文件操作相关

1. 读文件方式

第一种 有规律的名称
第二种 无规律的名称

2. 文件名称

用 “{:05d}” 来规范输出数字所占位数,例如:

for i in range(100):
      gt_file =  'Reference/' + 'image' + "{:05d}".format(i) + '.jpg'
      print(gt_file)
输出:
...
Reference/image00007.jpg
Reference/image00008.jpg
Reference/image00009.jpg
Reference/image00010.jpg
Reference/image00011.jpg
Reference/image00012.jpg
...

3. 存为mat文件

import scipy
from pathlib import Path

save_output = "home/xxx/data/"
path = Path(save_output, "output.mat")

with open(path , 'wb') as output_file:
   scipy.io.savemat(
       output_file,
       {
           "prob": pts, # pts 是变量,prob是mat文件中存储pts变量的矩阵名称
           "desc": desc
       }
   )
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值