python去掉文件名字里面的空格

 

import os

image_dir   = "./JPEGImages"
xml_dir     = "./Annotations"
txt_dir     = "./labels"

buff_dir = txt_dir
for files_name in os.listdir(buff_dir):
    if len(files_name.split(" ")) >1:
        os.rename(os.path.join(buff_dir,files_name),
                  os.path.join(buff_dir,files_name.replace(" ","_")))
        print(os.path.join(buff_dir,files_name.replace(" ","_")))

 

上一篇:以流的方式读取url中的参数


下一篇:Linux 内存释放