Common functions and methods

Source: Internet
Author: User


Find boundary

    Line_text.endswith ('my_case_'):    line_text.startswith ('my_ Case_')


Finding substrings

Url.find ('show)

Text extraction

Re.compile (R'\s+ (\d+):. *'). Sub (r'\1', Line_ Text)    #  Direct Intercept, no truncation will also return a string


Open the file and update

Open ('testone_config.json','w'). Write (' Sublime text ')

Test URL is valid

Import urllib.request    URL='http://www.baidu.com'    Try :        urllib.request.urlopen (urllib.request.Request (URL))    except  :        Sublime.status_message (")

Get Word

 #View video, Self.view    #Mark to find a point    defGet_word (view,mark,one=True): Func="'Mark_line=view.line (mark.a) func_a=View.substr (Sublime. Region (MARK_LINE.A,MARK.A)) Func_b=View.substr (Sublime. Region (mark.a,mark_line.b)) Back_b=re.findall (R'(^[ma\w_]+) [\ ' \ ' \ (]', Func_b) back_a=re.findall (R'[\ "\ ' >\.\s] ([\w_]+) $', Func_a)ifOne :ifBack_a andBack_b:func = back_a[0] +Back_b[0]Else:            ifBack_a:func=Back_a[0]ifback_b:func+=Back_b[0]returnFunc



Batch substitution for a page

 classFunc_tihuan_allcommand (Sublime_plugin. Textcommand):defRun (SELF,EDIT,TR): Mark=Self.view.sel () [0] func=Self.view.substr (Mark)iftr=='TP': Func= Func.replace ('src= "images/','src= "__public__/home/img/') Func= Func.replace ('src= "js/','src= "__public__/home/js/') Func= Func.replace ('URL (".. /images/','URL (".. /img/') Func= Func.replace ('URL (.. /images/','URL (.. /img/') Func= Func.replace ('href= "css/','href= "__public__/home/css/')            eliftr=='Tpweb': Func= Func.replace ('src= "images/','src= "__public__/home/web/img/') Func= Func.replace ('src= "js/','src= "__public__/home/web/js/') Func= Func.replace ('URL (.. /images/','URL (.. /img/') Func= Func.replace ('href= "css/','href= "__public__/home/web/css/')            eliftr=='Formatcss': Strinfo=re.compile (R'([^}]) \r\s+') Strinfo2=re.compile (R'([^}\n]{4,70}) \ n') Strinfo3=re.compile (R'([]{2,70})') Strinfo4=re.compile (R'(^[]{0,70})', Re. M) Strinfo5=re.compile (R'\n[\s]*\n') Func=strinfo.sub (R'\1', func) func=strinfo2.sub (R'\1', func) func=strinfo3.sub (R"', func) func=strinfo4.sub (R"', func) func=strinfo5.sub (R'\ n', func)eliftr=='TEJG': Func= Func.replace ('$GLOBALS [\ ' db\ ']','$db') Func= Func.replace ('$GLOBALS [\ ' ecs\ ']','$ecs') Func= Func.replace ('$GLOBALS [\ ' _cfg\ ']','$_cfg') Func= Func.replace ('$GLOBALS [\ ' _lang\ ']','$_lang') Func= Func.replace ('$GLOBALS [\ ' smarty\ ']->','$smarty')            eliftr=='Tezg': Func= Func.replace ('$db','$GLOBALS [\ ' db\ ']->') Func= Func.replace ('$ecs','$GLOBALS [\ ' ecs\ ']->') Func= Func.replace ('$_cfg','$GLOBALS [\ ' _cfg\ ']') Func= Func.replace ('$_lang','$GLOBALS [\ ' _lang\ ']') Func= Func.replace ('$smarty','$GLOBALS [\ ' smarty\ ']->') self.view.replace (edit, Mark, func);



Common functions and methods

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.