This time I will bring you the method of css file formatting script, what are the precautions of css file formatting script, the following is a practical case, let's take a look.
#!/usr/bin/python # -*- coding: UTF-8 -*- import sys,os def format(ddt): ddt = ddt.replace('\n','')#去除换行 ddt=ddt.replace(';}','}').replace(';',';\n').replace('{','{\n').replace('}','\n}\n')#重新换行 lines = ddt.split("\n")#读取全部换行内容 ddt="" for line in lines : ddt=ddt+line.strip(' ')+"\n"#去除每行前面空格 return ddt.replace('{\n','{\n ').replace(';\n',';\n ') #空格整理 for file in sys.argv: if file!=sys.argv[0] and os.path.isfile(file) and (str(file).split(".")[-1]).lower()=="css": print u"正在读取-",file newfile = open(file,"r") f=format(newfile.read()) newfile=open(file,'w') newfile.write(f) newfile.close() print file,"-ok"
I believe you have mastered the method after reading the case in this article. Please pay attention for more exciting things. php Chinese websiteOther related articles!
Related reading:
How to debug different versions of nodejs with different versions of vscdoe
##Vuejs webp supports image plug-in development
The above is the detailed content of How to format css file formatting script. For more information, please follow other related articles on the PHP Chinese website!