Home > Web Front-end > CSS Tutorial > How to format css file formatting script

How to format css file formatting script

php中世界最好的语言
Release: 2018-03-08 09:18:05
Original
1976 people have browsed it

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"
Copy after login

How to format css file formatting script

How to format css file formatting script

How to format css file formatting script

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template