使用Python脚本格式化压缩后的JS文件,,lines = open
文章由Byrx.net分享于2019-03-23 09:03:24
使用Python脚本格式化压缩后的JS文件,,lines = open
lines = open("unformated.js").readlines()[0].split(";")#一般压缩后的文件所有代码都在一行#里 视情况设定索引,我的情况时第0行是源代码。indent = 0formatted = []for line in lines: newline = [] for char in line: newline.append(char) if char=='{': #{ 是缩进的依据 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))#该片段来自于http://byrx.net
相关内容
- 字符串去重复值,字符串重复值,以前在实际应用时,需
- 九九乘法表,乘法,print '\\n'.
- urllib2抓取网页时的错误处理,urllib2抓取网页,try: u
- python列出文件夹下的所有文件,python列出文件夹,#方法
- Python队列和堆栈,Python队列堆栈,#For a stack
- python windows平台锁定键盘,python锁定,pywin32中没有Bl
- Python 获取邮件地址,python获取邮件地址,import email
- Python 最长公共子串算法,python串算法,#!/usr/bin/e
- Python 实现enum的功能,python实现enum,class Enumer
- python随机生成一个简单的密码代码,python生成代码,im
评论关闭