In viewmodel, C # property automatically adds the onpropertychanged tool and corresponding Python knowledge points.

Source: Internet
Author: User
In wpfmvvm, you often encounter adding private fields to the attributes of model and viewmodel and changing the notification method to support binding. For example, change: public class test {Public String testdata1 {Get; set;} Public String testdata2 {Get; Set ;}to: public class test: inotifypropertychanged {private string _ testdata1; public String testdata1 {get {return _ testdata1;} set {_ testdata1 = value; onpropertychanged ("testdata1") ;}} private string _ testdata2; public String testdata2 {get {return _ testdata2;} set {_ testdata2 = value; onpropertychanged ("t Estdata2 ") ;}} if you encounter many attributes, it will be too tired and error-prone. Therefore, I wrote a python tool specifically to add private fields and add method notifications. Since it was the first time I used python, I wrote down some knowledge points in the middle. 1) Use # to annotate the code, like: # Version: 12) use import to import other libraries, and like: Import RE3) Re is the regular expression library, shutil is the copy or backup file library 4) class definition, like: Class yourclassname: 5) definition of the constructor, like: def _ init _ (selft, yourparameter ): 6) method definition, like: def yourmethodname (self, yourparameter): 7) Self is similar to this pointer in C, C ++ 8) can a regular expression string in Python be used? P <your_key> to mark a conforming value, like: pattern = "((? P <space> \ s *) Public \ s + "testdata =" public "m = Re. match (pattern, testdata) print (M. group ('space') if there are many spaces at the beginning of a test data that meet the \ s * condition, we can use space as the keyword to index specific spaces. In this example, 4 spaces 9). You can use "% (your_key) s" % {'your _ key': your_value}, like: Self. classpattern = "(\ s * Public \ s + % (class) S \ s + % (derived) S \ s + % (colon) S + \ s * % (base) s) "% {'class':" class ", 'deleted':" \ W + ", 'colon':": ", 'base': Self. baseclassname} 10) If the string is cross-row, add \ 11) Re. the match () return value is none12 if it does not match.) You can convert the matching result of the regular expression into a dictionary, like: M = Re. match (pattern, testdata) yourdict = m. groupdict () 13) can use raise exception ("Your exception informati On ") to throw an exception 14) use lower () to convert the string to lowercase 15) Replace (old, new, length) to replace the string, and you can specify to replace several 16) input () can accept console input 17) If, else, for statement Definition: If methodname = "": methodname = "onpropertychanged" for line in filebackup: print ("line is: % s" % line) 18) file operations include open, write, close, and other methods, where open accepts open methods, for example, "R +" indicates read/write. "W +" indicates to clear the source file (if any) and then read and write 19). You can use cxfreeze to package py as the EXE file. After cxfreeze is installed, open the command line and go to the python path: C: \ python33 \ scripts. Use cxfreeze propertychanged. PY -- Install-Dir = D:/onpropertychanged after running successfully, the onpropertychanged directory will have EXE, python33.dll and related dependent PYD File Download: http://sourceforge.net/projects/cx-freeze? Source = dlp20) in addition, we found that tortoisegit and sublime text are very useful.

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.