This article describes the Python format of the compressed JS file method. Share to everyone for your reference. The specific analysis is as follows:
The script can be compressed JS file format for some restore, of course, will not be perfect, temporarily do not deal with grammar problems, just for the convenience of Reading JS code
Lines = open ("Unformated.js"). ReadLines () [0].split (";")
#一般压缩后的文件所有代码都在一行里
#视情况设定索引, the No. 0 line of my situation is the source code.
indent = 0
formatted = [] for line in
lines:
newline = [] for char in line
:
newline.append (char) C9/>if char== ' {': #{is the basis for indentation
indent+=1
newline.append ("\ n")
newline.append ("\ T" *indent)
if Char = = ":
indent-=1
newline.append (" \ n ")
newline.append (" \ T "*indent)
formatted.append (" \ t "* Indent+ "". Join (newline))
open ("Formated.js", "W"). Writelines ("; \ n". Join (formatted))
I hope this article will help you with your Python programming.