Python3 write CSS file format code __python

Source: Internet
Author: User

Some web pages have a messy CSS file format, written in 1 lines, such as:

To this end, we wrote a python3 script, the term format CSS file, the effect of formatting as shown:

#!usr/bin/env python  
#-*-coding:utf-8 _*-  
"" " 
@project: Normal_css
@author: Xiangguosun 
@ contact:sunxiangguodut@qq.com
@website: http://blog.csdn.net/github_36326955
@file: normal.py 
@ Platform:macos Sierra 10.13.1 pycharm Pro 2017.1 
@time: 2018/01/28 
"" "


def Normal (File_path, out): C11/>with Open (File_path, ' R ') as file:
        data = File.read ()
    outstring = Data.replace ("{", "{\ n"). Replace ("}", " \n}\n\n "). Replace ("; ","; \ n ") with
    open (out, ' W ') as outfile:
        outfile.write (outstring)

    print (" done! ")


if __name__ = = "__main__":
    normal (' origin.css ', ' normal.css ')

If you are editing under Webstorm, you can further tweak the command+option+l (Mac OS) to further indent, but I don't think it's necessary.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.