您的位置:首页 > 编程语言 > Python开发

python实现sublime3的less编译插件示例

2014-04-27 10:38 465 查看
import sublime, sublime_pluginimport urllibimport 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