python实现删除c语言文件的空格,注释

代码:
“”"
-- coding:utf-8 --
author:YY设计
datetime: 2019/10/12 0012 9:01
software: PyCharm
@Email : [email protected]
学习交流qq群:916696436
“”"
#读取字符
import re
def process(str):
print(‘processing:’,str)
t=[]
with open(‘text.txt’,encoding=‘utf-8’) as f:
for line in f.read():
t=t+list(line)
m="".join(t)
process(m)
result=re.sub(r’/{1}[].[*]/{1}’,"",m)#去掉/**/
st=list(result)
#去掉空格一行换行
for i in range(0,len(st)):
for line in st:
if '\n’in line:
index= st.index(line)
del st[index]
if ’ 'in line:
index= st.index(line)
del st[index]
if '\t’in line:
index= st.index(line)
del st[index]
mn="".join(st)

print(mn)
file = open(‘xie.txt’,‘w’)
file.write(‘mn’)
file.close()
结果前:
python实现删除c语言文件的空格,注释
结果后:
python实现删除c语言文件的空格,注释