context.py common module

1.context.py write regular expressions, the source code is as follows:

Re Import 
#s target string
#dict alternative content
# find the target identifier string inside KEY, to get inside the replacement value d
# s to replace the inside, and then returns Aberdeen

def replace (s, dict) :
P = "\ $ \ {(.? *)}"
the while the re.search (P, S) None Not IS:
m = the re.search (P, S)
Key m.group = (. 1)
value = dict [ Key]
S = the re.sub (P, value, S, COUNT =. 1)
return S

S = '{ "MobilePhone,": "admin_user $ {}", "pwd": "admin_pwd $ {}"}'
Data = { "admin_user": "17,799,801,359", "admin_pwd": "123456"}

S = Replace (S, Data)
Print (S)

 

Guess you like

Origin www.cnblogs.com/weihc/p/11893188.html