Python Combat: Scan Key Integrity

Source: Internet
Author: User

Previously in the international version, the need to support the Chinese and English switching function, in such a large variety of source files to find the source file key is the language resource package corresponds.

Just used the previous Python, wrote a tool to support custom replacement tags, batch processing source files. Now it seems that the effect is good enough to scan out the mismatched key.

Source File connection: Http://pan.baidu.com/s/1ntC78Zv

The challenges encountered during this period are:

The following key-value are present in the language pack: "I am; key\" \,\ ":" I am; Key\ "\,\"

The regular expression used before is this: Re.compile (' "(. *?)"), which only matches "I am key\".

There are a number of workarounds, and the methods I use are divided into several steps:

First, the whole sentence of the \ change to \, that is: "I am; key\\\": "I am; key\\\ "

Second, you can use Re.compile (' "(. *?)") to get to me; key\\\

Third, the replacement of the first step back, that becomes: I am; key\ "\,\"

Fd=open (Jsonfilepath,'R') Data=Fd.readline () whileData:data=data.decode ('Utf-8')    #print ' raw data: ' +data        #The first step, find the replacementP=re.compile (R'(\\.)') Keeper=p.findall (data)#print ' keeper:%s '%keeperData=p.sub (R'\\', data)#print ' first: ' +data     #Step two, find keyP2=re.compile (R'"(.*?)"') s=p2.search (data)ifnone!=S:data=s.group (1)     Else: Data=Fd.readline ()Continue     #print ' second: ' +dataresult="'          #step three, restore       forKeinchKeeper:target=data.find ('\\')          iftarget>=0:result=result+data[:target]+ke#print '----' +resultData=data[target+1:]               #print '--------' +dataResult=result+data

Result is the final outcome, and this succeeds in getting the normal language pack key, and the same principle of processing the source file

Python Combat: Scan Key Integrity

Related Article

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.