def _change(text1):
text1 = str(text1)
re_compile = re.compile("\${(.*?)}")
result_list = re.findall(re_compile, text1)
if len(result_list) == 0:
pass
elif len(result_list) == 1:
text2 = re.sub(re_compile, result_list[0], text1)
return text2
elif len(result_list) > 1:
for i in result_list:
print(i)
text1 = re.sub("\${%(can)s}" % {"can": i}, i, text1, 0)
if __name__ == '__main__':
data = {'${data}': {'${_id}': '56592efb22b', 'username': 'admin123',
'password': '123456'}}
print(_change(wqw))
我想将data转化为{'data': {'_id': '56592efb22b', 'username': 'admin123', 'password': '123456'}},不知道能不能实现(data可以是任何形式只要是${data}全部替换为data)