python table转空格

有需求:

 

预留,先上代码:

 1 import os
 2 
 3 def Table_Space(file_name,lis_out,tab_num = 4):
 4     file_str = open(file_name,"r").read()
 5     if "\t" in file_str:
 6         lis_out.append(file_name)
 7         print(file_name)
 8         open(file_name,"w").write(file_str.expandtabs(tab_num))
 9 
10 def Cyc_Fold(Fold_F,list_out):
11     for i in os.listdir(Fold_F):
12         if os.path.isdir(os.path.join(Fold_F,i)):
13             Cyc_Fold(os.path.join(Fold_F,i),list_out)
14         if os.path.isfile(os.path.join(Fold_F,i)) and (i.startswith("app") or i.startswith("hmi")) and (i.endswith(".c") or i.endswith(".h")):
15             Table_Space(os.path.join(Fold_F,i),list_out)
16 
17 if __name__ == "__main__":
18     list_out = []
19     Fold_in = input("Please input folder:")
20     Cyc_Fold(Fold_in,list_out)
21     file_out_name = os.path.join(Fold_in,"Modify_out.txt")
22     file_out = open(file_out_name,"w")
23     for i in list_out:
24         file_out.write(i + "\n")
25     file_out.close()

 

posted @ 2016-09-30 15:16  ply616  阅读(815)  评论(0编辑  收藏  举报