Python 格式化css文件,python格式化css,[Python]代码im
Python 格式化css文件,python格式化css,[Python]代码im
[Python]代码
import string, sysimport re, StringIOTAB=4def format(ss): f = open (ss, "r") data = f.read() f.close() dlen = len(data) i = 0 buf = StringIO.StringIO() start = 0 while i < dlen: if data[i] == '{': buf.write(data[start:i] + ' { ') i = i + 1 start = i elif data[i] == '}': last = string.strip(data[start:i]) if last: buf.write(' '*TAB + last + ';') buf.write(' } ') i = i + 1 start = i elif data[i] == ';': line = string.strip(data[start:i]) buf.write(' '*TAB + line + '; ') i = i + 1 start = i else: i = i + 1 buf.write(data[start:i+1]) return buf.getvalue()if __name__ == '__main__': if len(sys.argv) == 1: print 'usage: cssformat.py filename' sys.exit() ret = format(sys.argv[1]) print ret
相关内容
- Python threading模块,pythonthreading,[Python]代码#-
- Python base64模块,pythonbase64模块,[Python]代码#-
- Python MySQLdb模块,pythonmysqldb模块,[Python]代码#-
- Python ConfigParser模块,pythonconfigparser,[Python]代码#-
- Python HTMLParser模块,pythonhtmlparser,[Python]代码#-
- Python StringIO模块,pythonstringio模块,[Python]代码im
- Python zipfile模块,pythonzipfile模块,[Python]代码im
- Python 动态规划算法,计算单词距离,python算法,[Python]代
- Python 获取按键(跨平台),python获取按键,[Python]代码 c
- Python 读取mp3 ID3信息,python读取mp3id3,[Python]代码fr
评论关闭