python实现sublime3的less编译插件示例
2014-04-27 00:00
826 查看
利用http://tool.oschina.net/less 提供的接口,发送请求进行远程编译.
再将编译好的less,保存为同名后缀为css的文件中.
第一次使用python,代码也是拼拼凑凑的.需要加上线程进行异步请求,但是不会...
再将编译好的less,保存为同名后缀为css的文件中.
第一次使用python,代码也是拼拼凑凑的.需要加上线程进行异步请求,但是不会...
import sublime, sublime_plugin import urllib import json class exampleCommand(sublime_plugin.TextCommand): def run(self, edit): file_name=self.view.file_name(); if file_name.find('.less') == -1: print('only .less file can compile to css!!'); return; file_object_from = open(file_name); all_the_text = file_object_from.read(); url = "http://tool.oschina.net/action/less/less_compile"; data = all_the_text.encode(encoding='UTF8'); headers = {'User-Agent':'sublime_plugin'}; req = urllib.request.Request(url,data,headers); response = urllib.request.urlopen(req); the_page = response.read(); css=json.loads(the_page.decode("utf8"))['css']; file_object_to = open(self.view.file_name().replace('.less', '.css'), 'w') file_object_to.write(css); file_object_from.close(); file_object_to.close(); print(css);
相关文章推荐
- python实现sublime3的less编译插件示例
- K-means聚类算法介绍与利用python实现的代码示例
- python实现冒泡排序的简单示例
- 快速实现基于Python的微信聊天机器人示例代码
- Python实现基于PIL和tesseract的验证码识别功能示例
- Python实现的直接插入排序算法示例
- notepad++ pythonScript插件之去重并排序实现
- Python实现两款计算器功能示例
- Python实现在tkinter中使用matplotlib绘制图形的方法示例
- Python实现的根据文件名查找数据文件功能示例
- Python爬虫实现全国失信被执行人名单查询功能示例
- Python实现的生成格雷码功能示例
- Python 使用PIL numpy 实现拼接图片的示例
- 用http实现文件共享(python和go语言示例)
- css3实现可滑动跳转的分页插件示例
- php实现与python进行socket通信的方法示例
- Python基于tkinter模块实现的改名小工具示例
- python实现图片批量剪切示例
- jQuery使用zTree插件实现可拖拽的树示例
- python中Switch/Case实现的示例代码