zoukankan      html  css  js  c++  java
  • python 读取全部文件名以及路径,并且输出到txt

    import os
    txtName = "test.txt"
    f=file(txtName, "a+")
    dire="/media/tina/ET/caffe/SegNet_ip/CamVid/test/"
    anchor="/media/tina/ET/caffe/SegNet_ip/CamVid/testannot/"
    for root ,dirs, files in os.walk(dire):
        for file_single in files:
            test = dire+file_single
            refile = file_single[0:8]
            anchort = anchor + refile +'.png'
            result = test + " " +anchort +'
    '
            f.write( result)
    f.close()

    没写绝对路径,就会被认为是在当前文件夹,这个代码主要是研究生阶段各种实验用,我从两个功能代码拼接的。当然可能有更简洁美观的,欢迎留言交流。root里面存了绝对路径,不过由于我之后还要改,空格后面同一行的绝对路径,以及文件格式,所以直接写出来了。

    这就是把待标注的图像以及标签写到同一个txt。包括了他们的绝对路径。用的挺多的。

    这个代码会输出这样的txt:

    本博客专注于错误锦集,在作死的边缘试探
  • 相关阅读:
    74.QT窗口实现类的封装
    73,QT指针数组实战(指针数组与数组指针)
    72.函数模板指针与类函数模板的绑定
    71.lambda表达式的递归
    C++ new delete(一)
    ios之@class
    xcode菜单栏
    ios 自定义delegate(一)
    strong&weak
    TCP/UDP
  • 原文地址:https://www.cnblogs.com/SweetBeens/p/8696707.html
Copyright © 2011-2022 走看看